Jump to content

Script works fine but running AutoIt3 Syntax Checker gives lots of errors..


Recommended Posts

Hi

I made a very long and complex script, the end of this script i made a GUI this GUI have lots of Global variables.

I made some functions along the way that uses variables from the GUI , only after i launch my program from the GUI then this functions gets activated.

the script works fine , but when i try to use AutoIt3 Syntax Checker i get lots of error about "possibly used before declaration" variables

i think its because the function is written before i activate my GUI , but it will never WORK before i press activate button on that GUI

do i need to start moving functions or my GUI to the begining of the script , thats sounds a big stupid...

thanks for your help.

Link to comment
Share on other sites

If you want them to go away dim the variables you use inside your function. If you look at the check those show up as warnings and not errors (usually).

Link to comment
Share on other sites

Thanks for that info, also i have problems with a function that some times i call it with (ByRef $A,ByRef $:P and some times i call it with just ($C,$D)

some times i want to manipulate $A / $B inside that function and some time i don't want to. this also give me an error

also i made a Global variable inside one of the functions, i need it inside that function because its counting the time , starting with this function and moving on to the next function.. i use some thing like

function 1

Global $SEARCH_TIME = TimerInit()

....

.......

ENDFUNC

FUNCTION 2

IF $SEARCH_TIME >$WHATEVER THEN.....

ENDFUNC

is there something wrong with that ? why give me a warning ? or error ..

also

i made a function that will handle unxpected error , if the program im running would crash that will create a window, the window is not created untill the program crashes so i made a function to close the future error window

but Syntax Checker gives me an error

Link to comment
Share on other sites

You should always declare Globals outside functions. The function can still modify them but it's just bad practice to declare them inside a function. If your program crashes it won't call your function because it won't get a chance so show the code and we can help more.

Link to comment
Share on other sites

Ok this is an example for a function that i use to find out it the program that the script is working on have crashed

Func CHECKING_IS_PROGRAM_IS_RUNNING()

WinActivate("Microsoft Excel")

WinMove("Microsoft Excel", "", 0, 0)

Local $STATE = WinGetState("Microsoft Excel", "")

If $STATE == 0 Then

WinActivate("Error")

WinMove("Error", "", 0, 0)

MouseClick("left", 10, 10, 1, 10)

Send("{ENTER}")

WinActivate("Unrecoverable")

WinMove("Unrecoverable", "", 0, 0)

MouseClick("Unrecoverable", 10, 10, 1, 10)

Send("{ENTER}")

WinActivate("Excel")

WinMove("Excel", "", 0, 0)

MouseClick("Excel", 10, 10, 1, 10)

Send("{ENTER}")

START_EXCEL($Program_Name)

Return False

Else

Return True

EndIf

EndFunc

problem is that "Unrecoverable" and "error" will not be defind untill the program crash (its a window created after program crashes)

1 more thing

whats the best way to reset an array ?

right now im doing something like

Func Reset_array()

Local $INDEX = 0

While $INDEX <= 4999

$ARRAY[$INDEX][0] = ""

$ARRAY[[$INDEX][1] = ""

$ARRAY[[$INDEX][2] = ""

$ARRAY[[$INDEX][3] = ""

$INDEX = $INDEX + 1

WEnd

EndFunc

is there a better way ?

Edited by mrbig1479
Link to comment
Share on other sites

Oh I see, I thought you meant you were checking for your program's crash. You're using vista? Also for your array if you're going to do it that way why not just use a For ... Next loop? Besides you could just ReDim the array and reset its values.

Link to comment
Share on other sites

For Next is easier.

For $i = 0 To UBound($array)
$array[$i] = ""
Next

See? Vista has a lot of issues with stuff like this (not the For Next loop everything else) so I was wondering. Why not just declare it somehow? Or check if it exists with WinExists()?

Link to comment
Share on other sites

  • 2 weeks later...

I would like to share with everyone you how I dealt with the "possibly used before declaration" warnings.

1. I created a GlobalVariables.au3 file in my current project folder. Global variables used in multiple au3 source files are declared in this file. The file begins with an "#include-once" directive and is included in every au3 source file in the project.

2. My child forms are placed in the bounds of functions. The control handles are declared at the top of the file outside the bounds of any functions. Note: I had some test code in a dialog box file that activates the form running as what I suppose would be a main program of sorts (i.e. not Func/EndFunc, just a couple of statements at the beginning of the file). Variable declarations placed after this code (specifically the Exit statement) were ignored.

These two steps seem to have eliminated the warnings. in my project.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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