I have this code
'Open a file for reading
'Get a StreamReader class that can be used to read the file
Dim objStreamReader As StreamReader
Dim variableArray(20) As String
objStreamReader = File.OpenText(filePath)
'Read one line at a time
Dim someString As String
Dim variableNum As Integer = 0
'Iterate through lines
While objStreamReader.Peek() <> -1
someString = objStreamReader.ReadLine()
variableArray(variableNum) = someString
variableNum = variableNum + 1
End While
For Each line As String In variableArray
Next
objStreamReader.Close()
I have a vbscript that is outputting results in a log file, appended on each line and delimited by a “|” there will only be two columns.
Here is a snippet of the VBScript code
f1.WriteLine("Server Name " & "|" & strName)
f1.WriteLine("OS Name: " & "|" & strCaption)
f1.WriteLine("OS Version: " & "|" & strVersion
f1.WriteLine("CSD Version: " & "|" & strCSDVer
f1.WriteLine("Serial Number: " & "|" & strSerial
How can I get the For Each part of my code to read this, break it apart and then create a table showing the results.
Considering that you need two values from the variableArray in order to add a new row to the table, I would do a For..Next Loop (stepping by 2) instead of a For…Each:
Since you already have the amount of elements in your array stored in “variableNum”, you can just loop from 0 to that value, stepping by 2. Each iteration you’ll create two cells with the values of the current and next variables in the array. Then, those cells will be added to a row, which will in turn be added to the table.