Results 1 to 2 of 2

Thread: Saving information to a file

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    I need to save information to a file name, how do I write the code to a file? The code is from an prior answer
    that I got.
    Afterwards: How can I retrive the file name again?

    Code:
    'You can use Registry, which will store all those values.... 
    
    'in form_Load u can call the registry key which will give the previous stored value. 
    
    'here text1 stores the actual value of marks of a user(whose name is in text3), do give the name differently each time u save otherwise the previous value in the registry will be overwritten 
    
    'here text2 stores the actual value of average of a user(whose name is in text3) 
    
    Option Explicit 
    
    
    Private Sub Command1_Click() 
    'Save to Registry 
    SaveSetting App.Title, "Scores", "Marks" & Text3.Text, Text1.Text 
    
    SaveSetting App.Title, "Scores", "Average" & Text3.Text, Text2.Text 
    
    End Sub 
    
    Private Sub Command2_Click() 
    'Get the values from the Registry or u can write this code in the form Load event also thats up to U. 
    
    On Error GoTo y 
    Dim mysettings As Variant 
    Dim intsettings As Integer 
    List1.Clear 
    mysettings = GetAllSettings(App.Title, "Scores") 
    
    'Adds the series of marks and average values into a listbox serially from the registry 
    
    For intsettings = LBound(mysettings, 1) To UBound(mysettings, 1) 
    List1.AddItem mysettings(intsettings, 1) 
    Next intsettings 
    y: 
    If Err.Number = 13 Then 
    MsgBox "There are no Entries to Show", vbExclamation, "Error" 
    Exit Sub 
    End If 
    
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    Calgary, Canada
    Posts
    453
    To write data to a file use the following code:

    Code:
    open "c:\Temp\Data.dat" for output as #1
    
    For intsettings = LBound(mysettings, 1) To UBound(mysettings, 1) 
        Print#1, mysettings(intsettings, 1) 
    Next intsettings
    
    close #1
    To read it back use

    Code:
    open "c:\Temp\Data.dat" for input as #1
    
    while not EOF(1)
        input #1,strTemp
        list1.additem strTemp
    Wend
    
    Close #1
    I hope this is what you are looking for.

    SD
    "I'd rather have a full bottle in front of me than a full frontal lobotomy!"

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