|
-
November 8th, 1999, 10:49 PM
#1
How can I Randomize a list of text words
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, 03:36 AM
#2
Re: How can I Randomize a list of text words
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.
-
February 10th, 2009, 05:21 AM
#3
Re: How can I Randomize a list of text words
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]
-
February 10th, 2009, 10:18 AM
#4
Re: How can I Randomize a list of text words
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:
Code:
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
Last edited by WoF; February 10th, 2009 at 10:21 AM.
-
February 11th, 2009, 05:55 AM
#5
Re: How can I Randomize a list of text words
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..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
February 11th, 2009, 08:48 AM
#6
Re: How can I Randomize a list of text words
Really! I think I'd better start looking at the date stamp of the original post.
-
April 30th, 2009, 03:27 AM
#7
Re: How can I Randomize a list of text words
i overlooked the date part i am so sorry but i am not the only that is being fooled by the date
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
|