|
-
Jul 17th, 2008, 06:35 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] save/load
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
-
Jul 17th, 2008, 06:58 AM
#2
Re: save/load
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
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 17th, 2008, 07:16 AM
#3
Thread Starter
Fanatic Member
Re: save/load
i got one error
type missmatch
Print #F, Str(List1.List(i))
-
Jul 17th, 2008, 07:20 AM
#4
Re: save/load
Here is one Sub that does both. Modify as necessary
Code:
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
-
Jul 17th, 2008, 07:26 AM
#5
Thread Starter
Fanatic Member
Re: save/load
i get an runtime error 53...
-
Jul 17th, 2008, 07:34 AM
#6
Re: save/load
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)
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 17th, 2008, 07:36 AM
#7
Re: save/load
Also, change the following line:
Code:
For i = 0 To List1.ListCount
into
Code:
For i = 0 To List1.ListCount - 1
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 17th, 2008, 07:43 AM
#8
Re: save/load
 Originally Posted by Justa Lol
i get an runtime error 53...
On what line?
-
Jul 17th, 2008, 07:45 AM
#9
Thread Starter
Fanatic Member
Re: save/load
 Originally Posted by Hack
On what line?
never mind akhileshbc made it work for me thanks anyways
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|