|
-
November 29th, 2002, 08:01 AM
#1
How can I shuffle this listbox?
Hi,
I have a list box on my form which has 4 items in. I also have a buton (CmdShuffle). When I press the button I want the contents of the list box to shuffle around (i.e. change their position in the list).
Any info on how I can do this?
Thanks
Mark
-
November 29th, 2002, 08:30 AM
#2
There is no predefinite function to shuffle the content of a list box. Since you only have four items I don't think would be a problem if you were to remove all the items from the list box and then add them again in a different order. See ResetContent, rand, srand.
Matters of great importance must be treated lightly, matters of small importance can be treated seriously.
-
November 29th, 2002, 08:38 AM
#3
Any code for using ResetContent, Rand or Srand in this way...?
Thanks,
Mark.
-
November 29th, 2002, 09:18 AM
#4
The rand and srand are from C language, in VB, you'll have to use RND function. Look this example, it remove each elements (one after the others), and put re-insert them in a random position:
Code:
Private Sub Command1_Click()
Dim strItem As String
'Initialise random number generation
Randomize Timer
With List1
'Browse each list elements
For x = 0 To .ListCount - 1
'Remove the element, we'll add it after
strItem = .List(x)
.RemoveItem x
'Add the removed element to a random position
.AddItem strItem, Int(Rnd * .ListCount)
Next x
End With
End Sub
JeffB - hope it helps
-
November 29th, 2002, 09:54 AM
#5
Nice, JeffB
5 stars for you
Have happy coding,
Cesare
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
November 29th, 2002, 10:47 AM
#6
Thanks! Code works fine.
Mark
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
|