Link to home
Start Free TrialLog in
Avatar of questrel
questrelFlag for Ireland

asked on

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.
Avatar of aikimark
aikimark
Flag of United States of America image

try using the Read statement.  It is the opposite of the Write statement.
Avatar of questrel

ASKER

That didnt work unfortunately.

Perhaps i need to read the file into an array?
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

ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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