What is the fastest way to save data in an MSFLexGrid to a file and later bring it back in. I am using For Loops, but is there a quicker method like GET and PUT?
Printable View
What is the fastest way to save data in an MSFLexGrid to a file and later bring it back in. I am using For Loops, but is there a quicker method like GET and PUT?
Make a Type for the colums of data you have.
Example: First, Last, Phone, Address, City, State
Code:Private Type Contacts_t
First as string * 16
Last as string * 16
Phone as string * 8
Address as string 20
City as string * 20
State as string * 2
End Type
Dim Contacts() as Contacts_t
Now just Redim the Contacts array to the amound of rows in your flexgrid. Load up your array structure with data in your flexgrid and save it with the put command.
Hope this helps :-)
Sorry, but can you give me an example!
For instance I have two fields. First Name and Last Name in a MSFlexGrid! What should I do next.
I got the Put method down.
It would be great if you can provide a sample of actual codes.Code:'PURPOSE: Output to file method
Open App.Path & "\Zest.txt" For Binary As #1
Put #1, , str_Data
Close #1
Thank you again.
Sorry.. ok,
I really haven't used MSFlexGrid so im not to kean in it's properties. So bare with me.
What this will do is loop through your flex grid an put the first and last name data from each row into a new index in the Type Array.Code:Private Type Header_t
Rows as Integer
End type
Private Type Contacts_t
FirstName as string * 20
LastName as string * 20
End Type
Dim Contacts() as Contacts_t
Dim Header as header_t
Header.Rows = MSFlexGrid1.Rows
ReDim Contacts(MSFlexGrid1.Rows)
For i = 1 to MSFlexGrid1.Rows
Contacts(i).FirstName = MSFlexGrid1.Text ?
Contacts(i).LastName = MSFlexGrid1.Text ?
Next i
Open App.Path & "\Zest.txt" For Binary As #1
Put #1, , Header
Put #1, , Contacts
Close #1
Then When we are all done we just output the entire Type Array into a file.
To load the file back up you do this,
This is why we saved that header variable with the number of rows in it. We need to know how big to make the Contacts array before we fill it with values out of the file.Code:Open App.Path & "\Zest.txt" For Binary As #1
Get #1, Header
ReDim Contacts(Header.rows)
Get #1, Contacts
Close #1
Then just use a For loop agen to load up the data into the Flex grid from your Contacts Type Array.
Cool eh!
Just make sure when you write back to the file you delete the file first and then save your data.
Later,
[Edited by nkad on 10-16-2000 at 06:05 PM]
Thank you nkad!
It works!
:):)