-
Im trying to find if an item on a list is selected, and if an item is selected i want to get the index number and the item. im trying stuff using list1.selected, but it always gives me errors. Also how do you save the items in a listbox into a text file and reload it back to the form in the list form, i dont understand that.
-
Whew that's more than one little post.
I'll answer the second part first.
put this in either a module or the form:
Public Sub WriteData()
Open "YOUR FILE HERE" For Output As #1
For X = 0 To (YOURLIST.ListCount)
Write #1, YOURLIST.List(X)
Next X
Close #1
End Sub
Public Sub GetData()
Open "YOUR FILE HERE" For Input As #1
Do Until (EOF(1) = True)
Input #1, VARIABLE
If VARIABLE = "" Then
Else
YOURLIST.AddItem VARIABLE
YOURLIST.ItemData(YOURLIST.NewIndex) = 0
End If
Loop
Close #1
End Sub
Then "Call GetData" or "Call WriteData" to get the contents of the file and put them in the list box or put the contents of the list into a file. The file won't exist the first time you run it, so you probably want to add the lines:
Open "YOUR FILE HERE" For Random As #1
Close #1
That opens (or creates) the file and immediately closes it so you don't get an error file not found. Put it in the Form_Load event.
That should be all you need to do. You can edit the file from another program because it's straight up ascii. Also, the part that says if variable = "" else meanse that if it sees an empty line it will skip over it. remove that if you want the empty line in it.
good luck. email or post if you have further questions on this.
bob
-
heh heh. The first part was easier than I thought it would be. Try this:
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox (List1.ListIndex & ", " & List1.List(List1.ListIndex))
End Sub
it gives a message box with the index and the contents of the item clicked. hmm.
bob
-
thanks alot, your posts helped out alot. The second post kind of made me feel dumb, but i had 2 different lists with the same info almost, just changed around and i tried the listindex with the wrong one, oh well, anyway, both of the posts helped alot, thanks again.
-
No problem. I actually thought the second part would be a lot harder than it ended up being, but as I was messing with things while trying to program it, it just happened to work. I had expected a lot more work. You're very welcome.
bob