-
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
-
Code:
Open "c:\the file you want to write to.txt" For Output As #1
Print #1, "blah"
Print #1, strSomeString
Print #1, somethingElse
Close #1
Then to read the info from the file line by line and display it in a listbox ;
Code:
Dim strLine As String
Open "c:\the file you want to read in.txt" For Input as #1
Do Until Eof(1)
DoEvents
Line Input #1, strLine
List1.AddItem strLine
Loop
Close #1
-
Is it a ini file you want to make and read ?
-
Hi, and thanks!
Now I have tried to implement the statements and it works OK exept when clicking command button 2 without clicking command button 1. How can I write the information from the txt-file to the two text-boxes?
Best regards Hans Peter
Code:
Dim var1, var2 As String
Private Sub Command1_Click()
var1 = Text1.Text
var2 = Text2.Text
Open "c:\test.txt" For Output As #1
Print #1, var1
Print #1, var2
Close #1
End Sub
Private Sub Command2_Click()
Dim strLine As String
Open "c:\test.txt" For Input As #1
Do Until EOF(1)
DoEvents
Line Input #1, strLine
List1.AddItem strLine
Loop
Close #1
Text2.Text = var1
Text1.Text = var2
End Sub
:rolleyes:
-
Put the lines in an aray
Dim text(2) As String
i = 0
Open "c:\test.txt" For Input As #1
Do Until EOF(1)
DoEvents
i = i + 1
Line Input #1, strLine
List1.AddItem strLine
text(i) = strLine
Loop
Close #1
Text2.text = text(1)
Text1.text = text(2)
End Sub