Results 1 to 3 of 3

Thread: [RESOLVED] Randomize things?

  1. #1

    Thread Starter
    Banned
    Join Date
    Aug 2009
    Posts
    333

    Resolved [RESOLVED] Randomize things?

    I want to be able to randomize the SendKeys command, so what do I to to
    Code:
            SendKeys.Send("1")
            SendKeys.Send("2")
            SendKeys.Send("3")
            SendKeys.Send("4")
            SendKeys.Send("5")
    To make it send those in random order?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Randomize things?

    try this:

    vb Code:
    1. Dim randomNumber As New Random
    2. Dim usedNumbers As New List(Of Integer)
    3.  
    4. For x As Integer = 1 To 5
    5.     Dim number As Integer = randomNumber.Next(1, 6)
    6.     If Not usedNumbers.Contains(number) Then
    7.         usedNumbers.Add(number)
    8.         SendKeys.Send(number.ToString)
    9.     Else
    10.         x -= 1
    11.     End If
    12. Next

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

    Re: [RESOLVED] Randomize things?

    You might like to check this out.
    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

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