18.01.2013 Views

VBScript Reference Manual for InduSoft Web Studio

VBScript Reference Manual for InduSoft Web Studio

VBScript Reference Manual for InduSoft Web Studio

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>InduSoft</strong> <strong>Web</strong> <strong>Studio</strong> <strong>VBScript</strong> <strong>Reference</strong> <strong>Manual</strong><br />

Method: Close<br />

Description: Closes an open TextStream file<br />

Use: objTso.Close<br />

Arguments: objTso<br />

Required. The name of a TextStream Object previously instantiated.<br />

Return: None<br />

Remarks: The Close method closes the file, but still need to set the object variable to Nothing to release<br />

memory. (e.g. “Set objTso = Nothing”<br />

Example: Dim fso, f, myfile<br />

Set fso = CreateObject(“Scripting.FileSystemObject”) ‘Instantiate the FSO object<br />

myFile = $getAppPath() & “notes.txt” ‘Specify the app directory & file<br />

Set f = fso.CreateTextFile(myFile, True)<br />

f.WriteLine (“this is a note”)<br />

f.Close ‘Close the document<br />

Method: Read<br />

Description: Reads a specified number of characters from a TextStream file and returns the resulting string.<br />

Use: strChars = objTso.Read(numCharacters)<br />

Arguments: objTso<br />

Required. The name of a TextStream Object previously instantiated.<br />

numCharacters<br />

Required. The number of characters you want to read from the file<br />

Return: A specified number of characters from the file<br />

Remarks: None<br />

Example: Const ForReading=1, Const ForWriting=2, ForAppending=8<br />

Dim fso, f, myfile, s<br />

Set fso = CreateObject(“Scripting.FileSystemObject”) ‘Instantiate the FSO object<br />

myFile = $getAppPath() & “notes.txt” ‘Specify the app directory & file<br />

Set f = fso.OpenTextFile(myFile, ForReading)<br />

s = f.Read(10) ‘Read 10 characters<br />

MsgBox “First 10 characters = “ & s ‘Display<br />

f.Close ‘Close the document<br />

Method: ReadAll<br />

Description: Reads the entire TextStream file and returns the resulting string.<br />

Use: strChars = objTso.ReadAll<br />

Arguments: objTso<br />

Required. The name of a TextStream Object previously instantiated.<br />

Return: The entire TextStream file.<br />

Remarks: <strong>VBScript</strong> does not have a limit on the resultant character string length other than the available<br />

memory.<br />

Example: Const ForReading=1, Const ForWriting=2, ForAppending=8<br />

Dim fso, f, myfile, s<br />

Set fso = CreateObject(“Scripting.FileSystemObject”) ‘Instantiate the FSO object<br />

myFile = $getAppPath() & “notes.txt” ‘Specify the app directory & file<br />

Set f = fso.OpenTextFile(myFile, ForReading)<br />

s = f.ReadAll ‘Read entire file<br />

MsgBox “File contents = “ & s ‘Display it<br />

f.Close<br />

<strong>InduSoft</strong>, Ltd. 251

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!