• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1705
  • Last Modified:

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.
0
questrel
Asked:
questrel
  • 2
  • 2
1 Solution
 
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
 
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
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now