Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How do I read a text file using an array with SilkTest?

How do I read a text file using an array with SilkTest?

Below is an example of how to read a text file into SilkTest using an array:

[ ] ARRAY[100] OF STRING DataValues //declare array
[ ] integer arraycounter = 0
[ ] integer counter = 0
[ ]
[-] testcase Test1 () appstate none
[ ] String FullPath = "C:\HostData.txt" //read in Text file
[ ] ReadFile(FullPath)
[-] for (counter = 1; counter
[ ] print(DataValues[counter])

[-] ReadFile(String FilePath)
[ ] String LineRead
[ ] HFILE FileHandle = FileOpen (FilePath, FM_READ) //Opens txt file
[ ] print("The File being read is- {FilePath}")
[-] while(FileReadLine(FileHandle, LineRead)) //Returns the next line of the txt file
[ ] arraycounter++
[ ] DataValues[arraycounter] = LineRead
[ ] FileClose (FileHandle)

Running testcase Test1 will return the data from txt file C:\HostData.txt, as shown below:-
[-] Testcase Test1 - Passed
[ ] The File being read is- C:\HostData.txt
[ ] value1
[ ] value2
[ ] value3
[ ] value4
[ ] value5

Old KB# 29870


Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 20:40
Updated by:
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.