Jump to content

Is there a value for uninitialized variables?


Angel
 Share

Recommended Posts

Hi,

I'd like to know if I can safely assume that the value of an uninitialized (but declared) variable will be "".

Also, if that is the case, can I assume that to be the expected behaviour (i.e. part of the specification of the AutoIt language) and not likelly to change?

Basically, I am using some Global variables as "persistant" or "static" variables within a function:

Func myCallbackFunc()
   ; Declare the "pseudo-static" variable that keeps track of a editBox value
    Global $myCallbackFunc_previousValue

   ; Read the new contents of the editBox
    Local $myCallbackFunc_previousValue= GUICtrlRead($myEditBox)

   ; Check if the contents of the editBox changed
    If $myCallbackFunc_previousValue = $newValue Then
        Return
    EndIf

   ; If we get this far, the value in the editBox changed
    $previousValue = $newValue

   ; DO SOME WORK HERE

EndFunc

Basically I'd like to know if I need to declare and initialize to "" the Global variable $myCallbackFunc_previousValue outside of the function or not. I'd rather not, because then the codes looks more like if AutoIt really had support for static (persistant) variables.

My worry is that in some future version of AutoIt this code may not be valid anymore or if I enable "MustDeclareVars" it would at some point stop working.

Thanks for your opinions!

Angel

Link to comment
Share on other sites

if you dont give it a value it = ""

Thanks. I actually knew that, as I had verified it before posting my question. But what I'd like to know is whether this is the expected behavior or if this is just an unspecified behavior. The help file does not mention this, so I'd like to make sure that this is how it should be.

This seems to be a rather fundamental question about variable declaration in AutoIt...

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