Jump to content
Sign in to follow this  

Why an undefined variable error?

Recommended Posts


I've had great success using the GUIRegisterMsg command on forms having a single Input control. When I attempt to do the same with multiple Input fields as shown here, I receive the following error from SciTE.

==> Variable used without being declared.:

Case $txtBoxB

Case ^ ERROR

The code in the MessageHandler function doesn't do anything but display a MsgBox for this example, but I can't get it to even run. Furthermore, commenting-out any one of the (3) Case statements results in the same error message but referring to one of the other fields.

So, what am I missing?

#include <GUIConstants.au3>
#include <Misc.au3>
#include <Array.au3>
#include <GuiEdit.au3>

_Singleton( @ScriptName )
Global $TESTING = True

;- Initialize general variables
Global $i, $j, $k, $x, $y, $z ;- Temporary variables (some may not be used)
Global $gvEvent

;- Define Windows notification messages for an editbox. It's only a partial list, but it's more than we need
Global $gaMessageIndex = _ArrayCreate( False, False, False ) ;- One for each message
Global Const $WM_COMMAND   = 0x0111 ;- For registering message
Global Const $EN_SETFOCUS  = 0x0100 ;- Sent when an edit control receives focus
Global Const $EN_KILLFOCUS = 0x0200 ;- Sent when an edit control loses focus
Global Const $EN_CHANGE    = 0x0300 ;- Sent after field is altered and after it is displayed.
Global Const $EN_UPDATE    = 0x0400 ;- Sent after field is altered, but before it is displayed
GUIRegisterMsg( $WM_COMMAND, "_MessageHandler" )

Global $frmMain = GUICreate( "Test Messaging", 240, 135 )
Global $txtBoxA = GUICtrlCreateInput( "     ",  20,  20 )
Global $txtBoxB = GUICtrlCreateInput( "     ",  20,  40 )
Global $txtBoxC = GUICtrlCreateInput( "     ",  20,  60 )
Global $cmdQuit = GUICtrlCreateButton( "QUIT",  20,  90 )
For $i = 0 To UBound( $gaMessageIndex ) - 1 ;- Must reset array here or some indexes may be True
   $gaMessageIndex[$i] = False

;- Main loop
While True
   $gvEvent = GUIGetMsg()

   Case $gvEvent = $GUI_EVENT_CLOSE
   Case $gvEvent = $cmdQuit


GUIDelete( $frmMain )
Exit( 0 )

Func _MessageHandler( $hWnd, $gvEvent, $wParam, $lParam )
   Local $lnWinNotify  = _HiWord( $wParam ) ;- Notification message returned
   Local $lnWhichCtrl  = _LoWord( $wParam ) ;- Which control fired this message

   Switch $lnWhichCtrl
   Case $txtBoxA
      MsgBox( 0, "MsgA", $lnWinNotify )
   Case $txtBoxB
      MsgBox( 0, "MsgB", $lnWinNotify )
   Case $txtBoxC
      MsgBox( 0, "MsgC", $lnWinNotify )


Func _HiWord( $pvParam )
   Return BitShift( $pvParam, 0x10 )

Func _LoWord( $pvParam )
   Return BitAND( $pvParam, 0xFFFF )

Share this post

Link to post
Share on other sites

I think u need to use this


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post

Link to post
Share on other sites

GUIRegisterMsg( $WM_COMMAND, "_MessageHandler" )

in your code is set before you actually create the controls (and initialize those variables with controlIDs) , so it's not surprising that it complains about $txtBoxB or whatever being undeclared...

Edited by Siao

"be smart, drink your wine"

Share this post

Link to post
Share on other sites

Yep. That was it, Siao. Thanks!

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.