Jump to content

Recommended Posts

Posted

So I need some help...

basically all I want to do is have Autoit generate a random number between 1 and 3

and then have an if statement that reads the random number... and lets say if it = 3 it will say the number 3 in a msgbox

(like this)

sleep(500)

Random(1,3)

If Random = 2 Then
    MsgBox(0,"","2")
EndIf

If Random = 1 Then
    MsgBox(0,"","1")
EndIf

If Random = 3 Then
    MsgBox(0,"","3")
EndIf

can anyone help me? (thanks in advance!)

  • Moderators
Posted

TheFixer,

Get the random number and then use a Switch structure to distinguish between the 3 returns - look in the Help file to see the syntax.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 9/30/2015 at 10:00 AM, Melba23 said:

TheFixer,

Get the random number and then use a Switch structure to distinguish between the 3 returns - look in the Help file to see the syntax.

M23

I hope you don't mind but could you give me a little example? (I work best with examples & having things explained to me like I'm stupid pretty much lol)

  • Moderators
Posted

TheFixer,

What do you not understand about the example for Switch in the Help file? Does that not explain how to use the function well enough?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)
$iRandomNumber = Random(1, 3, 1)

Switch $iRandomNumber
    Case 1
        ; Code
    
    Case 2
        ; Code
    
    Case 3
        ; Code
EndSwitch

 

Edited by TheDcoder
speeling

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...