While Not EOF(hfile)
Line Input #hfile, buffer
Data() = Split(buffer, ",")
i = i + 1
With fghStudentInfo
.TextMatrix(i, 1) = Data(0)
End With
Wend

i'm new to VB.
can someone help me to understand the command?
i want to load the data from .csv to my vb interface.
when i use the code, it only insert the first column from my .csv file data. eg: a112233, batch, course1, course2 . In this case, it is a112233.
how can i make the next column for eg batch, course1, course2, to be loaded in the next column after a112233 in my interface ?
pls help. thank u so much !

Split function splits a string to substrings. Second argument is substring separator.

For example

Dim Data() As String

Data = Split("Comma,separated,values)", ",")
'Data(0) is "Comma"
'Data(1) is "separated"
'Data(2) is "values"

that was helpful !

now, if i put
Data() = Split(buffer, ",") ,
it only take the first value in my csv file.
how can i make the next data appear in my next column ?
can u tell?

tq so much for your respond.

Maybe the lines in your CSV file use some other separator than comma.

Put a breakpoint in the line Data = Split(buffer, ",") and check what the buffer-variable contains (is it something like "Comma,separated,values" or perhaps "NotComma;separated;values) and change the latter parameter in Split function accordingly, like Split(buffer, ";"). You can also open your csv-file with Notepad or similar and check what field separator character is used.

But the actual problem is in the way you display values. You do loop all the rows but you'll have to loop columns too. This may fix your loop

Dim j As Integer ' Column index
While Not EOF(hfile)
  Line Input #hfile, buffer
  Data() = Split(buffer, ",")
  i = i + 1 ' Row
  With fghStudentInfo
    ' Loop columns!!!
    For j = 0 To Data.GetUpperBound(0)
      .TextMatrix(i, j) = Data(j)
     Next j
  End With
Wend

You may get some "out of bounds" errors from that, but I'm sure you got the point what was "missing" in the original code.

This question has already been answered. Start a new discussion instead.