-
Hi I'm trying to save text that piles up in a listbox while my executable is running.
For example, a user would like to save their session, so they click a button and the contents in a listbox are saved to a text file or a log......
This seems easy enough to do?
Thanks For any help........
-
Try this:
Code:
Private Sub Command1_Click()
Dim i as Integer
Open "C:\Saved.txt" For Output As #1
For i = 0 to List1.ListCount
Print #1, List1.List(i)
Next i
Close #1
End Sub
Sunny
-
What if don't always know where the user will be installing my program, so therefore the textfile won't be accompained it.....
?
-
Then you can use the API to find out the Windows directory and put your file in there, everyone's bound to have a Windows directory.
Theres an example on how to do this in VB World at http://www.vb-world.net/tips/tip30.html
Sunny
-
Use App.Path to get the directory of your App.
Code:
Open App.Path & "\MyFile.txt" for Output As #1
For I = 0 to List1.ListCount
Print #1, List1.List(I)
Next I
Close #1
-
Thanks everyone, that worked great!
Now what about textboxes and saving text from them? Such as a users name. I want it all to happen on the same click
Heres my current code:
Private Sub Save_Click()
Dim i As Integer
Open "events.txt" For Output As #1
For i = 0 To Events.ListCount
Print #1, Events.List(i)
Next i
For i = 0 To Players.ListCount
Print #1, Players.List(i)
Next i
Close #1
End Sub
-
To save the text from TextBoxes.
Code:
Open "MyFile.txt" For Output As #1
Print #1, Text1.Text
Close #1
There, if this is saved with the rest, your code should be similar to the following:
Code:
Private Sub Save_Click()
Dim i As Integer
Open "events.txt" For Output As #1
For i = 0 To Events.ListCount
Print #1, Events.List(i)
Next i
For i = 0 To Players.ListCount
Print #1, Players.List(i)
Next i
'Save the text from Text1 as well
Print #1, Text1.Text
Close #1
End Sub