Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'save as' feature for msflexgrid

Status
Not open for further replies.

hinchdog

Programmer
Feb 14, 2001
380
US
i need to have a feautre that saves the data in a msflexgrid to a textfile.. then has the ability to open up the textfile into a new msflexgrid (reads the data)..does anyone have any code already to do this or can point me in the right direction. i'm sure it's been done before. thanks so much

-hinchdog
 
Hi Hinchdog

Try the following ...

Code:
Private Sub LoadSave(Grid As MSFlexGrid, Filename As String, Direction As String)
    Dim lngRow As Long
    Dim lngCol As Long
    Dim strCell As String
    
    Select Case Direction
        Case "Load"
            Open Filename For Input As #1
            With Grid
                For lngRow = 1 To .Rows - 1
                    For lngCol = 1 To .Cols - 1
                        Line Input #1, strCell
                        .TextMatrix(lngRow, lngCol) = strCell
                    Next lngCol
                Next lngRow
            End With
            Close #1
            
        Case "Save"
            Open Filename For Output As #1
            With Grid
                For lngRow = 1 To .Rows - 1
                    For lngCol = 1 To .Cols - 1
                        Print #1, .TextMatrix(lngRow, lngCol)
                    Next lngCol
                Next lngRow
            End With
            Close #1
            
    End Select
End Sub

To save the grid, call it as follows:

Code:
LoadSave MSFlexGrid1, "c:\tmp\junk.grd", "Save"

To load the grid, call it as follows:

Code:
LoadSave MSFlexGrid2, "c:\tmp\junk.grd", "Load"

Note:
This assumes that the two Grids are defined identically in terms of columns and rows (and fixed columns and rows). You could always save this information in the first four rows of the text file then compare them on load (and not load if they are different - issue an errow instead).



Hope this helps ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top