How to scramble a listbox

Posted on 2003-03-16
Medium Priority
Last Modified: 2010-05-01
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.
Question by:Gmoney
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

Shaka913 earned 500 total points
ID: 8147951
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

Expert Comment

ID: 8155805
Well? Did that work?

Author Comment

ID: 8171984
Yes it worked!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question