Click to See Complete Forum and Search --> : Read this and help me out.
Shark
Oct 16th, 2000, 01:41 PM
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?
nkad
Oct 16th, 2000, 01:58 PM
Make a Type for the colums of data you have.
Example: First, Last, Phone, Address, City, State
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 :-)
Shark
Oct 16th, 2000, 02:16 PM
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.
'PURPOSE: Output to file method
Open App.Path & "\Zest.txt" For Binary As #1
Put #1, , str_Data
Close #1
It would be great if you can provide a sample of actual codes.
Thank you again.
nkad
Oct 16th, 2000, 05:00 PM
Sorry.. ok,
I really haven't used MSFlexGrid so im not to kean in it's properties. So bare with me.
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
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.
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,
Open App.Path & "\Zest.txt" For Binary As #1
Get #1, Header
ReDim Contacts(Header.rows)
Get #1, Contacts
Close #1
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.
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]
Shark
Oct 16th, 2000, 08:14 PM
Thank you nkad!
It works!
:):)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.