|
-
Sep 10th, 2012, 01:46 AM
#1
Thread Starter
New Member
listbox movenext?
i am currently working on how to
movenext listbox or auto movenext
but after i execute it
it goes on the last record not on the next record
if i change the listcount to 1 a errors comes up, if i change the listcount to + 1 nothing happens...
i dont know why it was always goes on the last even i put + 1?
can anyone help me with this 
Code:
Dim i As Integer
For i = 0 To List1.ListCount - 1
i = i + 1
List1.Selected(i) = True
Text4.Text = List1.Text
Next
-
Sep 10th, 2012, 03:25 AM
#2
Re: listbox movenext?
You're manually changing the loop control variable (i) within the loop.
You need to remove the 'i = i + 1' statement
EDIT: Actually, what exactly are you trying to do ? By using a loop you'll always end up with the last item in the ListBox
EDIT: This code will move through the listbox items one at a time by clicking on Command2 button. When it reaches the end it starts over at the first item.
Code:
Private Function ListMoveNext(lst As ListBox, Optional boReStart As Boolean = False) As String
Static lngPos As Long
If boReStart Then lngPos = 0
If lngPos > lst.ListCount - 1 Then
ListMoveNext = vbNullString
Else
lst.Selected(lngPos) = True
ListMoveNext = lst.List(lngPos)
lngPos = lngPos + 1
End If
End Function
Private Sub Command2_Click()
Dim strItem As String
strItem = ListMoveNext(lst)
If strItem <> vbNullString Then
Text4.Text = strItem
Else
Text4.Text = ListMoveNext(lst, True)
End If
End Sub
Last edited by Doogle; Sep 10th, 2012 at 03:38 AM.
-
Sep 10th, 2012, 04:14 AM
#3
Re: listbox movenext?
Doesn't the Listbox support the For-Each Statement?
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
|