Results 1 to 5 of 5

Thread: Read this and help me out.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247
    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?
    Mako Shark
    Great White

  2. #2
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770
    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 :-)


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247

    Thanks for your reply

    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.


    Code:
      '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.
    Mako Shark
    Great White

  4. #4
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770
    Sorry.. ok,

    I really haven't used MSFlexGrid so im not to kean in it's properties. So bare with me.

    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
    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,
    Code:
    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]

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247
    Thank you nkad!

    It works!

    Mako Shark
    Great White

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width