-
Dec 27th, 2008, 04:41 AM
#1
Thread Starter
New Member
How to add an item into a ListBox during runtime
Hi,
I want to add new Items time by time into my ListBox after making exe file. If I put a command button, it places the new Item in the ListBox but it is temporary, it is not stored in the code. How can I make it permanent ?
Engin
-
Dec 27th, 2008, 05:47 AM
#2
-
Dec 27th, 2008, 06:31 AM
#3
Hyperactive Member
Re: How to add an item into a ListBox during runtime
try:
Code:
Private Sub Form_Load()
Dim strr As String
Open App.Path & "\ListFiles.txt" For Input As #2
Do Until EOF(2)
Input #2, strr
List1.AddItem strr
Loop
Close #2
End Sub
---------------------------------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
Open App.Path & "\ListFiles.txt" For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next i
Close #1
End Sub
"More Heads are Better than One"
-
Dec 28th, 2008, 02:08 PM
#4
Addicted Member
Re: How to add an item into a ListBox during runtime
list1.additem "item as string"
IT CTO & System Administrator.
-
Dec 29th, 2008, 08:53 AM
#5
Re: How to add an item into a ListBox during runtime
vb 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
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
|