FileReadValue Function


Reads structured data, for example, a 4Test record, directly from a file on the host system.


bResult = 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 FileReadValue to read information from files that are structured the same way that the FileWriteValue function structures files. The file must have only one value per line. 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. FileWriteValue does this automatically when it writes a record or list. Blank lines and lines starting with "/" are ignored. See FileWriteValue for more information about how to structure files for use with FileReadValue.

  • 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.

  • FileReadValue raises an exception if the read operation fails.

  • 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 can handle line lengths up to 4K characters.

  • This function is not designed for remote access.


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

[-] type PERSON is record
	[ ] STRING sName
	[ ] INTEGER iAge
	[ ] 
[-] STRING sFile = "people.dat"
	[ ] 
[-] testcase ReadFromFile()
	[ ] ANYTYPE Item
	[ ] HFILE hFile
	[ ] hFile = FileOpen(sFile, FM_READ) // Open the file
	[ ] while(FileReadValue(hFile, Item)) // Read from file
	[ ] Print(Item)
	[ ] FileClose(hFile)
	[ ] 
	[ ] // Result:
	[ ] // Number of people:
	[ ] // 3
	[ ] // {Bob, 46}
	[ ] // {Emily, 16}
	[ ] // {Craig, 13}