November 8th, 1999, 09:49 PM
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!
|
Click to See Complete Forum and Search --> : How can I Randomize a list of text words November 8th, 1999, 09:49 PM 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! November 9th, 1999, 02:36 AM 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. nekoanz February 10th, 2009, 04:21 AM 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 nekoanz26@yahoo.com WoF February 10th, 2009, 09:18 AM 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: Private Sub btnRand_Click() txtRand.Text = List1.List(Int(Rnd(1) * List1.ListCount)) End Sub I put it into a command button click to test it. Works fine. Have to add: the randomize timer statement nekoanz mentioned, is a good idea to create a different random sequence at every program start GremlinSA February 11th, 2009, 04:55 AM 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.. WoF February 11th, 2009, 07:48 AM :eek: Really! I think I'd better start looking at the date stamp of the original post. :rolleyes: nekoanz April 30th, 2009, 03:27 AM i overlooked the date part i am so sorry but i am not the only that is being fooled by the date codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |