Basic rotation tutorial on how to rotate 2 listbox's in a vb program. |
| First we nee to learn about list indexs. |
Property ListIndex As Integer
Returns/sets the index of the currently selected item in the control. |
| To change a list index you need to do this. List1.ListIndex = List1.ListIndex + 1 That will tell the program that the list1 index is equal to its list index + a new index. If you wanted to go back an index you would need to add. List1.ListIndex = List1.ListIndex - 1 That will tell it that the list index is equal to the list index minus 1 index. |
| Now that we know what an index is it is very simple to make them rotate. You can two this many ways and in many functions. You can add a rotation to a timer, in the return data of a winsock or anywhere else you would like. For this tutorial I'm going to put my listindex in a Timer. |
| I'm my form i have a Timer named Rotate / Properties: Interval = 0: Enabled = False. A Combo box with the intervals inside it, 100, 250, 500 ect ect |
| Make a button and put inside that button |
Rotate.Enabled = True ' start the timer
Rotate.Interval = Combo1.Text ' set the timer interval
status.Caption = "rotating" |
| This will start the timer and the actions inside the timer. |
| Now that the timer is starting, lets add the code inside the timer to make it rotate. Double click on your timer and add the following code so that when the timer is enabled then it will execute our actions. |
On Error Resume Next ' next procedure
Rotate.Interval = Combo1.Text ' incase this changed it will notice the change
List1.ListIndex = List1.ListIndex + 1 ' basic make the list move to its next index
If List1.ListIndex = List1.ListCount - 1 And List2.ListIndex = List2.ListCount - 1 Then ' both lists are at their end. complete rotation
Rotate.Enabled = False ' stop the timer, lists are done
status.Caption = "complete"
Else
If List1.ListIndex = List1.ListCount - 1 Then: List1.ListIndex = 0: List2.ListIndex = List2.ListIndex + 1 ' if list1 is at its end then list2 will goto its next index
End If |
| That's it. That code will rotate your lists. Once list1 is at its end then list2 will goto its next index. When both boxes reach their end then the timer will stop and the list rotations are complete. |
| Create a new button to stop our timer. |
Rotate.Enabled = False ' stop the timer
status.Caption = "stopped" |
| That's all there is to it. Enjoy |
|
|
#
12704
|
Rotating Two Listboxes :: by __Doc_ |
Source code by __Doc_, The source code can be found on the source code page. |
|