1. 程式人生 > 實用技巧 >在CRT螢幕上獲取某個具體位置的文字(轉)

在CRT螢幕上獲取某個具體位置的文字(轉)

可以使用Screen 物件的Get() or Get2()方法去獲取螢幕上的資料.

1 Get() 函式包含四個引數.文字第一個字元所在的行號,列號.最後個字元所在的行號與列號.

可以通過選擇相應的文字來檢視文字所處的行號與列號.

1342083382_5429.JPG


以下就可獲取相應的值.

nFreeMem = crt.Screen.Get (5,36,5,41)

把資料寫放到文字中

Writing data to a file using the VBScript FileSystemObject can typically be accomplished using

the following general steps:

1) Get a reference to the FileSystemObject :

Set objFSO = CreateObject( "Scripting.FileSystemObject" )

2) Use the FileSystemObject reference to retrieve a reference to a TextStream object

associated with the text file to which the data is to be written.

Const ForWriting = 2

Const ForAppending = 8

' Create a new file (or overwrite an existing one)

Set objStream = objFSO.OpenTextFile( _

"C:\Temp\MyDataFile.txt", _

ForWriting, _

True)

' Append to an existing file (create if it doesn't exist)

Set objStream = objFSO.OpenTextFile( _

"C:\Temp\MyDataFile.txt", _

ForAppending , _

True)

3) Write the data to the file using the TextStream object's Write or WriteLine methods.

The WriteLine method automatically appends EOL characters to the end of the data

supplied to the method.

objStream.Write "This data is written "

objStream.Write "as one single line."

Or:

objStream.WriteLine "This data is written "

objStream.WriteLine "as two separate lines."

Note that you can write multiple lines using either method by manually inserting CRLF

sequences as needed, for example:

bjStream.Write "This is line one." & vbcrlf & _

"This is line two." & vbcrlf & _

"This is line three." & vbcrlf & _

"This is line four." & vbcrlf


Or:


objStream.WriteLine "This is line one." & vbcrlf & _

"This is line two." & vbcrlf & _

"This is line three." & vbcrlf & _

"This is line four."


4) When you have completed writing data to the file, close the file:

objStream.Close


EXAMPLE:獲取CPU資料並將其寫入到檔案中

# $language = "VBScript"

# $interface = "1.0"

Sub Main ()

For x = 1 To 10000

crt.sleep 300000

usrCpu = crt.Screen.Get(2,7,2,9)

sysCpu = crt.Screen.Get (2,15,2,18)

idleCpu =crt.Screen.get(2,35,2,37)


Dim fso, f1

Set fso = CreateObject("Scripting.FileSystemObject")

Set f1 = fso.OpenTextFile("E:\TestFile.txt", 8,True)

f1.writeline("usr:" & usrCpu & " sysCpu:" & sysCpu & " idleCpu" & idleCpu)

f1.close


Next


end Sub


轉載於:https://blog.51cto.com/onthewaycjh/1339220