Results 1 to 7 of 7

Thread: randomize a word in a textbox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    307

    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."

  2. #2
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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:
    1. dim chr() As Char = "somewhere".ToCharArray
    2. dim Letters As New Arraylist
    3. For each c as char in chr
    4.  Letters.Add(c)
    5. 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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    307

    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."

  4. #4
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: randomize a word in a textbox

    VB Code:
    1. Dim newWord as string
    2. dim r as random
    3. dim i as integer
    4. Do While Letters.Count > 0
    5.   i = r.Next(Letters.Count-1)
    6.   newWord &= Letters(i)
    7.   Letters.RemoveAt(i)
    8. Loop

    that loops, picking randomly from the array of letters until no more letters are left to choose from

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: randomize a word in a textbox

    VB Code:
    1. Dim myArrayList As New ArrayList
    2.  
    3. myArrayList.AddRange(myString.ToCharArray())
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Posts
    307

    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."

  7. #7
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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
  •  



Click Here to Expand Forum to Full Width