TheFixer Posted September 30, 2015 Posted September 30, 2015 So I need some help...basically all I want to do is have Autoit generate a random number between 1 and 3and 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") EndIfcan anyone help me? (thanks in advance!)
ahmet Posted September 30, 2015 Posted September 30, 2015 $RandomNumber=Random(1,3,1) MsgBox(0,"Result",$RandomNumber)
TheFixer Posted September 30, 2015 Author Posted September 30, 2015 $RandomNumber=Random(1,3,1) MsgBox(0,"Result",$RandomNumber) not exactly what i was looking for I want it to be like If $RandomNumber = 3 Then --> does stuff here EndIf
Moderators Melba23 Posted September 30, 2015 Moderators Posted September 30, 2015 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 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
TheFixer Posted September 30, 2015 Author Posted September 30, 2015 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.M23I 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 Melba23 Posted September 30, 2015 Moderators Posted September 30, 2015 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 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
TheDcoder Posted September 30, 2015 Posted September 30, 2015 (edited) $iRandomNumber = Random(1, 3, 1) Switch $iRandomNumber Case 1 ; Code Case 2 ; Code Case 3 ; Code EndSwitch Edited September 30, 2015 by TheDcoder speeling TheFixer 1 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
TheFixer Posted September 30, 2015 Author Posted September 30, 2015 $iRandomNumer = Random(1, 3, 1) Switch $iRandomNumer Case 1 ; Code Case 2 ; Code Case 3 ; Code EndSwitch Thank you very much
TheDcoder Posted September 30, 2015 Posted September 30, 2015 My pleasure 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now