Dim FileLine As String
Dim LastName As String
Dim FirstName As String
Dim Age As Integer
Dim Salary As Currency
Dim Title As String
Dim StartPos As Integer
Dim CommaPos As Integer
Dim Count As Integer
Open "C:\test.csv" For input as #1
While Not EOF(1)
If EOF(1) Then GoTo ReadAll
Line Input #1, FileLine
StartPos = 1
'This for 1 to 5 loop would actually be For 1 To Number of vars
For Count = 1 To 5
'For all but the last variable, find the ending comma
'for the last variable just go from the last comma + 1
'to the end of the line
If Count < 5 Then
CommaPos = InStr(StartPos, FileLine, ",")
CurVar = Mid(FileLine, StartPos, CommaPos - StartPos - 1)
StartPos = CommaPos + 1
Else
CurVar = Mid(FileLine, CommaPos + 1)
End If
'now put the section of the fileline into the correct variable
Select Case Count
Case 1
LastName = Trim(CurVar)
Case 2
FirstName = Trim(CurVar)
Case 3
Age = Val(Trim(CurVar))
Case 4
Salary = Val(Trim(CurVar))
Case 5
Title = Trim(CurVar)
End Select
Next Count
Wend
ReadAll:
Close #1
MsgBox "FirstName = '" & FirstName & "'"
MsgBox "LastName = '" & LastName & "'"
MsgBox "Age = '" & Age & "'"
MsgBox "Salary = '" & Salary & "'"
MsgBox "Title = '" & Title & "'"