Jump to content

Script Works Perfectly, but a question about "Warning"


Recommended Posts

I have a Parent script that has 1 Child file that is included, so let's call if "Parent.au3" and "Child.au3" for ease. In Parent.au3, there is a Func that calls "CallChildFunc($Variable)" and passes the variable $Variable. Upon compiling, the Scite console reads:

"WARNING: $Variable: possibly used before declaration...- 0 error(s), 1 warning(s)"

Since the script works fine, I have no functional concerns about it, however from an academic standpoint, is there a better way for me to do what I am doing? Some way that would avoid a warning, or some standardised way that a Programming teacher would have tought me in Programming class to declare/pass variables when using #include? I am home-grown for scripting, so I missed a lot of this basic stuff.

Thanks.

Link to comment
Share on other sites

I have a Parent script that has 1 Child file that is included, so let's call if "Parent.au3" and "Child.au3" for ease. In Parent.au3, there is a Func that calls "CallChildFunc($Variable)" and passes the variable $Variable. Upon compiling, the Scite console reads:

"WARNING: $Variable: possibly used before declaration...- 0 error(s), 1 warning(s)"

Since the script works fine, I have no functional concerns about it, however from an academic standpoint, is there a better way for me to do what I am doing? Some way that would avoid a warning, or some standardised way that a Programming teacher would have tought me in Programming class to declare/pass variables when using #include? I am home-grown for scripting, so I missed a lot of this basic stuff.

Thanks.

A could thing to do is to always declare your variables with dim/local/global before using them, you can also add Opt("MustDeclareVars",1) to force yourself into declaring them.

You could also double click the warning in the scite console to jump to the warning so you can see for yourself that you have declared it.

My guess for this warning is that you use a global variable in your include which you declare in your main app.

:)

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

I have a Parent script that has 1 Child file that is included, so let's call if "Parent.au3" and "Child.au3" for ease. In Parent.au3, there is a Func that calls "CallChildFunc($Variable)" and passes the variable $Variable. Upon compiling, the Scite console reads:

"WARNING: $Variable: possibly used before declaration...- 0 error(s), 1 warning(s)"

Since the script works fine, I have no functional concerns about it, however from an academic standpoint, is there a better way for me to do what I am doing? Some way that would avoid a warning, or some standardised way that a Programming teacher would have tought me in Programming class to declare/pass variables when using #include? I am home-grown for scripting, so I missed a lot of this basic stuff.

Thanks.

Are you saying that there are people out there who are not 'home-grown'?

Presumably the variable $Variable1 is assigned some value before the function is called. Either that is done in a Global scope, i.e outside of a function, in which case add a declaration near the start of the script,

Global $Variable1

or $Variable1 is assigned inside a function, in which case add

Local $variable1

at the start of the function.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

...you can also add Opt("MustDeclareVars",1) to force yourself into declaring them.

You could also double click the warning in the scite console to jump to the warning so you can see for yourself that you have declared it.

Thanks, I did not know you could double-click the warnings!

Are you saying that there are people out there who are not 'home-grown'?

Presumably the variable $Variable1 is assigned some value before the function is called. Either that is done in a Global scope, i.e outside of a function, in which case add a declaration near the start of the script,

Global $Variable1

or $Variable1 is assigned inside a function, in which case add

Local $variable1

at the start of the function.

Hehe, I guess I might say there are those that are not 'home-grown', but I am for sure not saying that I am anything special for being 'home-grown'. If anything, I just like to point out that there are some blaring basics that I seem to have missed that are obvious for others.

Also, thanks for the 'rule' on Global/Local that is helpful. Making the $Variable Global fixed the warning. Thanks

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