Dave Cullen
2/19/2011 11:28:00 PM
I have nice little module that reads CSV lines of a text file, removes the
commas, and displays the 4 items/line in nice columns.
It works with a test file of 3 lines, but when there are 1 or 2 lines in the
file, it thows a Run time Error 9, Subscript out of range.
Here is the text file contents:
0,Phy Plant,Mech Rm Temp,2/19/2011 12:24:54 AM
3,Equip Mon,R,2/19/2011 12:30:55 AM
here is my code:
------------------
Private Sub Command3_Click() '-- Active Events Display test ---
Dim field() As String
Dim sTemp As String
Dim nI As Integer
Dim TmpTxt As String
FileNum = FreeFile
Tabulator(1) = 20
Tabulator(2) = 30
Tabulator(3) = 55
' Tabulator(4) = 250
' Tabulator(5) = 310
Dim strSQL As String
List1.Clear
Dim strMes As String
'Open App.Path & "\" & "MList.log" For Input As #1
Open "C:\" & "MList.log" For Input As #1
Do Until eof(1)
Line Input #1, TmpTxt
'ListView1.AddItem TmpTxt
field = Split(TmpTxt, ",", 4, vbTextCompare)
For nI = 0 To UBound(field)
sTemp = field(nI)
Next nI
SendMessage List1.hwnd, _
LB_SETTABSTOPS, OBorder, Tabulator(1)
sTemp = field(2) & Space(19 - Len(field(2))) '<- 9, Sup Script OORange
error
List1.AddItem " " & field(0) & vbTab & field(1) & vbTab & sTemp & vbTab &
field(3)
Loop
Close #1
End Sub
------------
The two lines of the file are correctly displayed as intended, the error
occurrs at EOF or some end fail.
Any suggestion greatly appreciated.