jamespagedev Posted March 27, 2020 Posted March 27, 2020 I can't figure out why I'm getting this error "variable used without being declared" (see attached image). Here is the script. expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Func Quit() Exit EndFunc Func MoveMouseToStartOrSkipAndClick() sleep(1000) MouseMove(1065, 637, 5) sleep(1000) EndFunc Func MoveMouseOffBannerAndClick() sleep(1000) MouseMove(1048, 771, 5) sleep(1000) EndFunc Func MoveMouseToSkipConfirmationAndClick() sleep(1000) MouseMove(977, 675, 5) sleep(1000) EndFunc Func Start() $numberOfLoops = 61 For $a1 = 2 TO $numberOfLoops MoveMouseToStartOrSkipAndClick() sleep(1000) If $al = 6 Then MoveMouseToSkipConfirmationAndClick() sleep(1000) MoveMouseToStartOrSkipAndClick() EndIf If $al = 11 Then sleep(40000) EndIf If $al = 12 Then MoveMouseToSkipConfirmationAndClick() sleep(1000) MoveMouseToStartOrSkipAndClick() EndIf If $al = 18 Then MoveMouseToSkipConfirmationAndClick() sleep(1000) MoveMouseToStartOrSkipAndClick() EndIf If $al = 24 Then MoveMouseToSkipConfirmationAndClick() sleep(1000) oveMouseToStartOrSkipAndClick() EndIf If $al = 30 Then MoveMouseToSkipConfirmationAndClick() sleep(1000) MoveMouseToStartOrSkipAndClick() EndIf If $al = 36 Then MoveMouseToSkipConfirmationAndClick() sleep(1000) MoveMouseToStartOrSkipAndClick() EndIf If $al = 42 Then MoveMouseToSkipConfirmationAndClick() sleep(1000) MoveMouseToStartOrSkipAndClick() EndIf If $al = 48 Then MoveMouseToSkipConfirmationAndClick() sleep(1000) MoveMouseToStartOrSkipAndClick() EndIf If $al = 54 Then MoveMouseToSkipConfirmationAndClick() sleep(1000) MoveMouseToStartOrSkipAndClick() EndIf sleep(40000) MoveMouseOffBannerAndClick() sleep(1000) Next ; comment out function Quit() to keep script running until ESC key is pressed Quit() EndFunc ;*********************** ;* program starts here * ;*********************** HotKeySet ("#{n}", "Start") ; Calls function to start program HotKeySet ("{ESC}", "Quit") ; Calls function to exit program immediately ;wait for the hotkey to be pressed While 1 Sleep(100) WEnd
RTFC Posted March 27, 2020 Posted March 27, 2020 (edited) There's a difference between $a1 and $aL! Edited March 27, 2020 by RTFC nikooo1608, Danp2 and Musashi 3 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
seadoggie01 Posted March 27, 2020 Posted March 27, 2020 I highly suggest using AutoItSetOption("MustDeclareVars", True) at the top of all of your scripts. It enforces good programming practices and helps catch those error before you run the program Alternately, you can edit the AutoIt3Wrapper.ini file and set the AU3Check_Parameter line to something like this: (this will apply to every file running Au3 check) AU3Check_Parameter=-d -w 3 -w 4 -w 5 -w 6 -v3 Musashi 1 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
Musashi Posted March 27, 2020 Posted March 27, 2020 (edited) @jamespagedev : You can substitute the multiple If..Then : Switch $al Case 6, 12, 18, 24, 30, 36, 42, 48, 54 MoveMouseToSkipConfirmationAndClick() Sleep(1000) MoveMouseToStartOrSkipAndClick() Case 11 Sleep(40000) EndSwitch You should also get into the habit of declaring the variables and giving them more explicit names (not $al <> $a1). 36 minutes ago, seadoggie01 said: I highly suggest using AutoItSetOption("MustDeclareVars", True) at the top of all of your scripts. Edited March 27, 2020 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
RTFC Posted March 27, 2020 Posted March 27, 2020 (edited) Switch $al @Musashi: There's a difference between $a1 and $aL! Edited March 27, 2020 by RTFC seadoggie01 and Musashi 2 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
Musashi Posted March 27, 2020 Posted March 27, 2020 28 minutes ago, RTFC said: @Musashi: There's a difference between $a1 and $aL! Oh F**k . My eyes don't get better with age either. Here the whole function without the annoying variable name : Func Start() Local $numberOfLoops = 61 For $iNum = 2 TO $numberOfLoops MoveMouseToStartOrSkipAndClick() sleep(1000) Switch $iNum Case 6, 12, 18, 24, 30, 36, 42, 48, 54 MoveMouseToSkipConfirmationAndClick() Sleep(1000) MoveMouseToStartOrSkipAndClick() Case 11 Sleep(40000) EndSwitch Sleep(40000) MoveMouseOffBannerAndClick() Sleep(1000) Next ; comment out function Quit() to keep script running until ESC key is pressed Quit() EndFunc RTFC 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
jamespagedev Posted March 27, 2020 Author Posted March 27, 2020 lol thanks. I knew going corporate would wipe out my programming skills. Thanks everyone for catching the typo and offering the refactoring.
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