|
-
Jan 25th, 2006, 12:33 AM
#1
Thread Starter
Hyperactive Member
randomize a word in a textbox
how can randomize a word in a textbox, for example if the word is cat it would randomize the letters to like cta or tac or something?
"Anybody can get angry or sad and frown but it takes a person with character to smile when times are hard."
-
Jan 25th, 2006, 12:40 AM
#2
Re: randomize a word in a textbox
i would store the letters in an arraylist, then in a loop, call random numbers which pick from the arraylist and remove each lette rone by one.
VB Code:
dim chr() As Char = "somewhere".ToCharArray
dim Letters As New Arraylist
For each c as char in chr
Letters.Add(c)
Next
then when you make the word, perform a loop, use randomize to pick a random number between 0 and (letters.count-1), and dont forget to .removeAt the index picked, so that it is not picked again.
Hope i explained well enough
-
Jan 25th, 2006, 12:52 AM
#3
Thread Starter
Hyperactive Member
Re: randomize a word in a textbox
i'm sorry but can you explain the random solution again, i don't understand.
"Anybody can get angry or sad and frown but it takes a person with character to smile when times are hard."
-
Jan 25th, 2006, 01:00 AM
#4
Re: randomize a word in a textbox
VB Code:
Dim newWord as string
dim r as random
dim i as integer
Do While Letters.Count > 0
i = r.Next(Letters.Count-1)
newWord &= Letters(i)
Letters.RemoveAt(i)
Loop
that loops, picking randomly from the array of letters until no more letters are left to choose from
-
Jan 25th, 2006, 01:02 AM
#5
Re: randomize a word in a textbox
VB Code:
Dim myArrayList As New ArrayList
myArrayList.AddRange(myString.ToCharArray())
-
Jan 25th, 2006, 01:15 AM
#6
Thread Starter
Hyperactive Member
Re: randomize a word in a textbox
to add the items to a listbox would i got listbox1.add.items(newword) right before the loop?
"Anybody can get angry or sad and frown but it takes a person with character to smile when times are hard."
-
Jan 25th, 2006, 01:30 AM
#7
Re: randomize a word in a textbox
right after the loop, that loop constructs newWord
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
|