-
I've got a filelistbox, and I want it to have a certain file selected when the form loads. I know it's probably a newbie question, but how can i do that? =)
I've tried several things, and havent been able to do it. I keep getting runtime errors, whenever I try something.
Any help would be appreciated.
Thanks,
Stephen
-
Try something like:
Code:
Private Sub Form_Load()
Dim lIndex As Long
For lIndex = 1 To File1.ListCount
If File1.List(lIndex) = "SomeFile.txt" Then
File1.ListIndex = lIndex
Exit For
End If
Next
End Sub
-
You could also use:
Code:
File1.ListIndex = 0
Or you can randomize it:
Code:
Function randomnumber(finished)
Randomize
randomnumber = Int((Val(finished) * Rnd) + 1)
End Function
Private Sub Command1_Click()
i = randomnumber(File1.ListCount)
File1.ListIndex = i
End Sub