Dieuz Posted April 19, 2007 Share Posted April 19, 2007 (edited) Hi, I got an error when I try to run a gui cases like that one (it's just a sample to show where my problem is): #include <GuiConstants.au3> GuiCreate("My GUI", 515, 585,-1, -1) $Button_a = GuiCtrlCreateButton("Enter", 348, 270, 150, 40) Guisetstate() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg= $Button_a GuiCtrlDelete($Button_a) $Button_b = GuiCtrlCreateButton("Back", 348, 480, 100, 20) Case $msg = $Button_b Exitloop EndSelect WEnd Exit This is giving me: Variable used without being declared.: Case $msg = $Button_b Case $msg = ^ ERROR How could I solve my problem? Edited April 19, 2007 by Dieuz Link to comment Share on other sites More sharing options...
therks Posted April 19, 2007 Share Posted April 19, 2007 (edited) That's because $Button_b doesn't exist until you press $Button_a. All the variables have to exist when the Select or Switch starts. *Edit: Try this. (Oops, forgot code tags) #include <GuiConstants.au3> GuiCreate("My GUI", 515, 585,-1, -1) $Button_a = GuiCtrlCreateButton("Enter", 348, 270, 150, 40) $Button_b = GuiCtrlCreateButton("Back", 348, 480, 100, 20) GUICtrlSetState($Button_b, $GUI_HIDE) Guisetstate() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg= $Button_a GUICtrlSetState($Button_a, $GUI_HIDE) GUICtrlSetState($Button_a, $GUI_SHOW) Case $msg = $Button_b Exitloop EndSelect WEnd Exit Edited April 19, 2007 by Saunders My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Dieuz Posted April 19, 2007 Author Share Posted April 19, 2007 (edited) So your saying that I should create all my controls at the beginning of my script and then use HIDE/SHOW? If the buttons is invisible, is it clickable? If yes should I use $GUI_ENABLE/DISABLE? Edited April 19, 2007 by Dieuz Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 19, 2007 Share Posted April 19, 2007 The only change you needed was to declare $Button_b before the Select. You were using it in the Select Case before it had been set by creating the replacement button. #include <GuiConstants.au3> GuiCreate("My GUI", 515, 585,-1, -1) $Button_a = GuiCtrlCreateButton("Enter", 348, 270, 150, 40) Dim $Button_b Guisetstate() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg= $Button_a GuiCtrlDelete($Button_a) $Button_b = GuiCtrlCreateButton("Back", 348, 480, 100, 20) Case $msg = $Button_b Exitloop EndSelect WEnd Exit Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
therks Posted April 19, 2007 Share Posted April 19, 2007 (edited) @Psalty: Did you try running that code first? It quits right away. That's because when you just Dim a variable, it defaults to 0. So the line Case $msg = $Button_b evaluates to Case $msg = 0 And what does GUIGetMsg() return when nothing's happening? That's right, 0. That's why I suggested he actually create the control first. That way the control ID is set and there's nothing to worry about.@Dieuz: It's not clickable through normal means, no, because you can't see it to click on it. But I do believe that if you use something like ControlClick() you can click it whether it's hidden or not, so depending on how worried you are about it you can apply the $GUI_DISABLE state as well.Something like GUICtrlSetState($Button_b, $GUI_HIDE+$GUI_DISABLE) should work.Although I should point out, if your end user is smart enough to use ControlClick, then they're probably smart enough to use ControlEnable and ControlShow as well. The most secure way of making sure that the user can't properly use the Button_b before you want them to is to have multiple conditions for your statement. Something like setting an extra variable to True when they click on Button_a, then doing Case $msg = $Button_b And $ExtraCondition = True But to be honest, I don't imagine you need it to be all that secure. Am I right?*Edit: Also, by all rights, if you want to go the lazy route like Psalty () then you could just Dim the variable before your code but set it to something like -99 (I suggest a high [or low rather] negative so you don't interfere with what could eventually be another control ID). Edited April 19, 2007 by Saunders My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 19, 2007 Share Posted April 19, 2007 @Psalty: Did you try running that code first? It quits right away. That's because when you just Dim a variable, it defaults to 0. Nope. Not on a Windoze box and could only run it in my head, so couldn't test it. You're right about $Button_b being defaulted and matching GuiGetMsg() for idle though, and initializing to a non-zero would probably fix it. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now