Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

How to scramble a listbox

Can anyone show me a true effcient way of scambling the list of listboxes.  Please don't use provide links. I've already used most links provided because I've asked this question before. I need strong code that is bonifided, orginal, and creative.
0
Gmoney
Asked:
Gmoney
  • 2
1 Solution
 
Shaka913Commented:
Please define scrambling? Do you mean put the list in a random order?

Below is some code for you. Create a form, add a listbox called List1, and 2 command buttons (Command1 and Command2)

Command1 will create an ordered list of 1 to 100
Command2 will scramble the list

run the scrambler is as much as you want to make it more random.

Option Explicit
 Const NumberOfElements = 100

Private Sub Command1_Click()
    Dim zI As Integer
   
    For zI = 1 To NumberOfElements
        List1.AddItem zI
    Next zI
End Sub

Private Sub Command2_Click()
    Dim zRnd As Integer
    Dim zTmp As Integer
    Dim zI As Integer
   
    Call Randomize(NumberOfElements)
    For zI = 0 To NumberOfElements - 1
        zRnd = Int((NumberOfElements * Rnd) + 1)
        If zRnd <> zI Then
            zTmp = List1.List(zI)
            List1.List(zI) = List1.List(zRnd)
            List1.List(zRnd) = zTmp
        End If
    Next zI
End Sub

Let me know if this helps
Good luck
0
 
Shaka913Commented:
Well? Did that work?
Thanks
0
 
GmoneyAuthor Commented:
Yes it worked!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now