Sign in to follow this  
Followers 0
Hauke

"Case $Button" causes script to not start

4 posts in this topic

Hello, I have a problem:
I wanted to create a little quiz with some basic questions. But the last command (Case $b_mann     MsgBox(1,"test","blup")) causes my script to not work. Sorry if my question is silly, but i am very new to auto it. If i just not write this command, everything works fine. I hope u can help me :^)
 
 
 
 
 
 
 
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$GUI_main = GUICreate("Idiotentest", 554, 331, 344, 162)
GUISetBkColor(0xFFFFFF)
$Label1 = GUICtrlCreateLabel("Dies ist ein Idiotentest. Beantworte alle Fragen richtig, ", 40, 8, 451, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("um zu beweisen, dass du keiner bist.", 40, 40, 314, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Wollen wir anfangen?", 168, 88, 186, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$b_klar = GUICtrlCreateButton("Klar!", 88, 176, 121, 49)
$b_nein = GUICtrlCreateButton("Nein!", 312, 176, 121, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $b_nein
Exit
Case $b_klar
GUISetState(@SW_HIDE,$GUI_main)
$name = InputBox("Anfang","Super! Dann lass uns beginnen.. Ähm... Wie war dein Name noch gleich?")
$GUI_frage1 = GUICreate("1. Frage", 615, 438, 303, 115)
            $Label1 = GUICtrlCreateLabel($name & "! Tut mir Leid wie konnte ich das bloß vergessen?", 80, 16, 600, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
            $Label2 = GUICtrlCreateLabel("Lass uns mit der ersten Frage beginnen:", 48, 96, 289, 24)
            GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
            $Label3 = GUICtrlCreateLabel("Bist du ein Mann oder eine Frau?", 72, 136, 500, 24)
            GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
            $b_mann = GUICtrlCreateButton("Mann", 56, 232, 217, 73)
            $b_frau = GUICtrlCreateButton("Frau", 312, 232, 249, 73)
            GUISetState(@SW_SHOW)

Case $b_mann
MsgBox(1,"test","blup")




EndSwitch
WEnd
 
 
 
 
 

Share this post


Link to post
Share on other sites



What doesn't work? 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The error received (I assume you are using the full version of AutoIt), tells you where the problem lies. You declare the variable $b_mann inside a Case statement, but attempt to use it in the next statement, so it is out of scope.

If you would use it, you would need to declare it higher in the statement. Something like this:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$GUI_main = GUICreate("Idiotentest", 554, 331, 344, 162)
GUISetBkColor(0xFFFFFF)
$Label1 = GUICtrlCreateLabel("Dies ist ein Idiotentest. Beantworte alle Fragen richtig, ", 40, 8, 451, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("um zu beweisen, dass du keiner bist.", 40, 40, 314, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Wollen wir anfangen?", 168, 88, 186, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$b_klar = GUICtrlCreateButton("Klar!", 88, 176, 121, 49)
$b_nein = GUICtrlCreateButton("Nein!", 312, 176, 121, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Local $b_mann
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $b_nein
Exit
Case $b_klar
GUISetState(@SW_HIDE,$GUI_main)
$name = InputBox("Anfang","Super! Dann lass uns beginnen.. Ähm... Wie war dein Name noch gleich?")
$GUI_frage1 = GUICreate("1. Frage", 615, 438, 303, 115)
            $Label1 = GUICtrlCreateLabel($name & "! Tut mir Leid wie konnte ich das bloß vergessen?", 80, 16, 600, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
            $Label2 = GUICtrlCreateLabel("Lass uns mit der ersten Frage beginnen:", 48, 96, 289, 24)
            GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
            $Label3 = GUICtrlCreateLabel("Bist du ein Mann oder eine Frau?", 72, 136, 500, 24)
            GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
            $b_mann = GUICtrlCreateButton("Mann", 56, 232, 217, 73)
            $b_frau = GUICtrlCreateButton("Frau", 312, 232, 249, 73)
            GUISetState(@SW_SHOW)
Case $b_mann
MsgBox(1,"test","blup")
 

EndSwitch
WEnd

This, however, will cause the MsgBox to continually show. I'll leave it to you to fix your logic.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

you could do this

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$GUI_main = GUICreate("Idiotentest", 554, 331, 344, 162)
GUISetBkColor(0xFFFFFF)
$Label1 = GUICtrlCreateLabel("Dies ist ein Idiotentest. Beantworte alle Fragen richtig, ", 40, 8, 451, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("um zu beweisen, dass du keiner bist.", 40, 40, 314, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Wollen wir anfangen?", 168, 88, 186, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$b_klar = GUICtrlCreateButton("Klar!", 88, 176, 121, 49)
$b_nein = GUICtrlCreateButton("Nein!", 312, 176, 121, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$b_mann = 0
While 1
    $nMsg = GUIGetMsg()
    if $nMsg <> '' then
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $b_nein
            Exit
        Case $b_klar
            GUISetState(@SW_HIDE, $GUI_main)
            $name = InputBox("Anfang", "Super! Dann lass uns beginnen.. Ähm... Wie war dein Name noch gleich?")
            $GUI_frage1 = GUICreate("1. Frage", 615, 438, 303, 115)
            $Label1 = GUICtrlCreateLabel($name & "! Tut mir Leid wie konnte ich das bloß vergessen?", 80, 16, 600, 28)
            GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
            $Label2 = GUICtrlCreateLabel("Lass uns mit der ersten Frage beginnen:", 48, 96, 289, 24)
            GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
            $Label3 = GUICtrlCreateLabel("Bist du ein Mann oder eine Frau?", 72, 136, 500, 24)
            GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
            $b_mann = GUICtrlCreateButton("Mann", 56, 232, 217, 73)
            $b_frau = GUICtrlCreateButton("Frau", 312, 232, 249, 73)
            GUISetState(@SW_SHOW)

        Case $b_mann
            MsgBox(1, "test", "blup")

    EndSwitch
    EndIf
WEnd
 

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.

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  
Followers 0