I need the code so that I can have a list of names (text) that will randomly pick one of those and display it in the assigned textbox, please help!! Stuck!
Printable View
I need the code so that I can have a list of names (text) that will randomly pick one of those and display it in the assigned textbox, please help!! Stuck!
An idea...
Put the words into an array and while you're in a loop
get two random indexes and swap the elements accordingly.
Let it loop some times, it depends on the number of words.
Then you have a random list of words.
All you have to do now, is to get element by element from
the first to the last.
in my way of doing it
you need to have two listboxes
the first one will have the list of the original values meaning the raw list of data then the second listbox will have the randomize jumbled list of data
sub randomizeList()
dim list1Len,i as integer
list1Len = list1.ListCount
while list1.listcount >0
rndIndex = Rnd * List1.Listcount
list2.additem list1.list(rndIndex)
list1.removeitem rndIndex
wend
end sub
then to avoid having the same set of random data
private sub form_activate()
randomize timer
end sub
give me feedback if ever you have problems
can't guarantee your satisfaction
i am just a student here
may e-add is [email protected]
Having the text items in a ListBox is not a bad idea, because you can make it visible during program developement and see what's in there.
Assuming List1 to contain your collection of texts, txtRand being the TextBox for the result, you select an item randomly to be displayed like this:
I put it into a command button click to test it. Works fine.Code:Private Sub btnRand_Click()
txtRand.Text = List1.List(Int(Rnd(1) * List1.ListCount))
End Sub
Have to add: the randomize timer statement nekoanz mentioned, is a good idea to create a different random sequence at every program start
This thread is almost 10 years old... I would think that the problem has been long solved..
nekoanz, I respect that you were trying to help someone out with your first post, however try to answer the more pressing questions (ie. those in the last few days).....
Gremmy..
:eek: Really! I think I'd better start looking at the date stamp of the original post. :rolleyes:
i overlooked the date part i am so sorry but i am not the only that is being fooled by the date