Loading a textfile into MSFlexGrid (VB6)

Hi,

I am very new to the use of MSFlexGrid


I have saved the data in my flexgrid to a csv file using the code below

For iRow = 0 To 49
        For iCol = 0 To 49
            Write #iFileHandle, MSFlexGrid1.TextMatrix(iRow, iCol);
        Next iCol
            Write #iFileHandle,
Next iRow

Open in new window


That part is working fine.

I am having some trouble loading the file back into flexgrid after though.  I am using the code below and it isn't working

For iRow = 0 To 49
    For iCol = 0 To 49
        Line Input #iFileHandle, sLineIn
            MSFlexGrid1.TextMatrix(iRow, iCol) = Split(sLineIn, ",")
    Next iCol
Next iRow

Open in new window


I would appreciate if someone could show me the error of my ways.
questrelAsked:
Who is Participating?
 
ArkCommented:
Dim s As String
For iRow = 0 To 49
        s=""
        For iCol = 0 To 49
            If s<>"" Then s=s & ","  
            s=s & MSFlexGrid1.TextMatrix(iRow, iCol)
            Write #iFileHandle, s
        Next iCol
        Write #iFileHandle
Next iRow

Open in new window

For iRow = 0 To 49
        Line Input #iFileHandle, sLineIn
        dim values() As String 
        values=Split(sLineIn, ",")
    For iCol = 0 To 49
           if Ubound(values)>=i Then
               MSFlexGrid1.TextMatrix(iRow, iCol) = values(icol)
           end if
    Next iCol
Next iRow

Open in new window

0
 
aikimarkCommented:
try using the Read statement.  It is the opposite of the Write statement.
0
 
questrelAuthor Commented:
That didnt work unfortunately.

Perhaps i need to read the file into an array?
0
 
aikimarkCommented:
what do you see in the flexgrid?

My expectation is that you will see an empty cell in each row, starting with the second row. If that is the case, then you should remove the additional Write statement at the end of each row.
Write #iFileHandle,

Open in new window

0
 
questrelAuthor Commented:
Thank you Ark.  That has helped me to read in the data

Here is the code which works for me

OpenFile

    For iRow = 0 To 49
        Line Input #iFileHandle, sLineIn
        Dim values() As String
        values = Split(sLineIn, ",")
        For iCol = 0 To 49
           If UBound(values) >= iCol Then
               MSFlexGrid1.TextMatrix(iRow, iCol) = values(iCol)
           End If
        Next iCol
    Next iRow

Open in new window


SaveFile

For iRow = 0 To 49
        For iCol = 0 To 49
            Write #iFileHandle, MSFlexGrid1.TextMatrix(iRow, iCol);
        Next iCol
            Write #iFileHandle,
Next iRow

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.