Jump to content
Sign in to follow this  
mrbig1479

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

Recommended Posts

mrbig1479

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.

Share this post


Link to post
Share on other sites
dbzfanatic

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).

Share this post


Link to post
Share on other sites
mrbig1479

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

Share this post


Link to post
Share on other sites
dbzfanatic

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.

Share this post


Link to post
Share on other sites
mrbig1479

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

Share this post


Link to post
Share on other sites
dbzfanatic

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.

Share this post


Link to post
Share on other sites
mrbig1479

Im not using Vista why ?

for- next loop is faster then while wend loop ?

Share this post


Link to post
Share on other sites
dbzfanatic

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()?

Share this post


Link to post
Share on other sites
RickJ

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.

Share this post


Link to post
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
Sign in to follow this  

×