i just want a button to be save and one for load and when i click save it just saves a file with everything on the list and loads that again if i click on the load button
Printable View
i just want a button to be save and one for load and when i click save it just saves a file with everything on the list and loads that again if i click on the load button
Use the below code:
:)Code:Private Sub cmdLoad_Click()
Dim F
Dim Temp As String
F = FreeFile
Open "c:\file1.dat" For Input As #F
Do While Not EOF(F)
Input #F, Temp
List1.AddItem Temp
Loop
Close #F
MsgBox "Loaded"
End Sub
Private Sub cmdSave_Click()
Dim F
F = FreeFile
Open "c:\file1.dat" For Output As #F
For i = 0 To List1.ListCount
Print #F, Str(List1.List(i))
Next i
Close #F
MsgBox "Saved"
End Sub
i got one error
type missmatch
Print #F, Str(List1.List(i))
Here is one Sub that does both. Modify as necessaryCode:Private Sub SaveLoadListbox(plstLB As ListBox, _
pstrFileName As String, _
pstrSaveOrLoad As String)
Dim strListItems As String
Dim i As Long
Select Case pstrSaveOrLoad
Case "save"
Open pstrFileName For Output As #1
For i = 0 To plstLB.ListCount - 1
plstLB.Selected(i) = True
Print #1, plstLB.List(plstLB.ListIndex)
Next
Close #1
Case "load"
plstLB.Clear
Open pstrFileName For Input As #1
While Not EOF(1)
Line Input #1, strListItems
plstLB.AddItem strListItems
Wend
Close #1
End Select
End Sub
Private Sub Form_Load()
Call SaveLoadListbox(List1, "c:\Listbox.txt", "load")
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call SaveLoadListbox(List1, "c:\Listbox.txt", "save")
End Sub
i get an runtime error 53...
Sorry, I used to str()... because in the sample program that I had created, listbox is filled with numbers only...
You can replace it with the following line:
Code:Print #F, List1.List(i)
Also, change the following line:
intoCode:For i = 0 To List1.ListCount
:)Code:For i = 0 To List1.ListCount - 1
On what line?Quote:
Originally Posted by Justa Lol
never mind akhileshbc made it work for me :D thanks anywaysQuote:
Originally Posted by Hack