Jump to content

Recommended Posts

Posted

I can't figure out why I'm getting this error "variable used without being declared" (see attached image).

 

Here is the script.

#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

 

auto_it_error.png

Posted

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

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 functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Posted (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.

:thumbsup:

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted
28 minutes ago, RTFC said:

@Musashi: There's a difference between $a1 and $aL! :rolleyes:

Oh F**k :lol:. 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

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...