SYS_FileReadValue Function


Reads structured data, for example a 4Test record, directly from a file on a target machine.


bResult = SYS_FileReadValue (hFile, aValue)
Variable Description
bResult TRUE if the read operation is successful; FALSE if at end of file. BOOLEAN.
hFile A handle to the file. HFILE.
aValue The data read from the file. ANYTYPE.


Use SYS_FileReadValue to read information from files that are structured the same way that the SYS_FileWriteValue function structures files. The file must have only one value per line. SYS_FileReadValue reads the data in a record or list as a single value, so make sure that all elements of a record or list are on the same line (SYS_FileWriteValue does this automatically when it writes a record or list). Blank lines and lines starting with "/" are ignored. See SYS_FileWriteValue for more information about how to structure files for use with SYS_FileReadValue.

SYS_FileReadValue is executed by the Agent process, not the Silk Test Classic process; but it is essentially the same as FileReadValue. To affect the host process, use the function with the hHost notation or machine handle operator. For more information about the machine handle operator and hHost, see Machine handle operator.

SYS_FileReadValue raises an exception if the read operation fails.

You can get a handle to a file (an HFILE) by calling the SYS_FileOpen function with the FM_READ filemode data type. An exception is raised if an invalid file handle is specified. You can read from a file opened in file mode FM_UPDATE, in order to begin overwriting the file in the middle instead of at the beginning. See the example under FileReadLine function.

4Test recognizes that it has reached the end of a file (EOF) by no longer reading that file –in other words, by receiving a null string. It does not read any special character at the EOF.

For Silk Test Classic, EOF is indicated by a FALSE bDidRead return and a null string is indicated by a TRUE bDidRead return and a null string.

This function is not designed for local access.


The following example uses the file that was created in the example for SYS_FileWriteValue.

type PERSON is record

STRING sFile = "people.dat"

testcase ReadFromFile ()
hFile = SYS_FileOpen (sFile, FM_READ) // Open the file
while (SYS_FileReadValue (hFile, Item)) // Read from file
Print (Item)
SYS_ FileClose (hFile)

// Result:
// Number of people:
// 3
// {Bob, 46}
// {Emily, 16}
// {Craig, 13}