GetString - read a string from a file into a variable

Return to Introduction  Previous page  Next page

$return = GetString(filename,line#[,onErrorLabel:])

Where:

$returnreceives 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.        
onErrorLabel:is 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 $FILEERROR 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

 

$Line = GetString(c:\test.txt,1)

$Line = GetString(c:\test.txt,1,IOError:)

$Line = GetString($FileName,$LineNumber)

 

Sample Script

 

' GetString.txt

' Sample script to read a file.

'

$Filename = c:\sample.txt

$LineNumber = 1

 

LOOP:

$Line = GetString($Filename,$LineNumber)

if $FILEERROR = 14 then GoTo EndOfFile:

if $FILEERROR <> 0 then GoTo IOError:

$LineNumber = $LineNumber,+,1

GoTo LOOP:

 

EndOfFile:

exit

 

IOError:

MsgBox("IO error. Return code = " & $FILEERROR)

exit

 

See Also:

 

PutString Command

Script Command Summary

Script Variables

Using the Scripting Language

 


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