GetString - read a string from a file into a variable

Return to Introduction  Previous page  Next page

GetString $variable,filename,line#[,label:]

Where:

$variablereceives the text read from the file.        
filenameis the full filename, including drive letter and path name for the input file. This file must be a text file. Enclose the filename in double quotation marks ("") if it contains embedded spaces or commas.
line#is the line number of the line to be read from the input file.        
labelis the label of an error handler routine. The script branches to this routine if the I/O fails. The I/O error handler routine can use the $FILESTAT variable to get the cause of the error. If this parameter is omitted, the user will be prompted with the script error dialog box which allows the command to be retried or ignored.

 

filename and line# may be variables.

The GetString command reads a line of text from a file and copies it into a script variable.

Examples

 

GetString        $LINE,c:\test.txt,1
GetString        $LINE,c:\test.txt,1,IOError:
GetString        $Line,$FileName,$LineNumber

 

Sample Script

 

* GetString.txt

* Sample script to read a file

*

SetVar $FileName,f:\script\sample.txt

SetVar $LineNumber,1

SetVar $Lines,4

 

LOOP:

GetString $Line,$FileName,$LineNumber

type $Line

key "enter"

CalcVar $LineNumber,$LineNumber,+,1

if $LineNumber,LT,$Lines,LOOP:

 

Exit

 

See Also:

 

Script Command Summary

Script Variables

Using the Scripting Language

PutString Command


TN3270 Plus is continually being improved. To learn more about the latest enhancements, please review our Version History web page.