Jump to content
Sign in to follow this  
Captnplanet

Having trouble creating a "Survey"

Recommended Posts

Captnplanet

#include <GUIConstants.au3>

$Count = 0
GUICreate("Question 1", 400, 250)
$labela = Guictrlcreatelabel ("Question here", 10, 10, 360, 120)
$radio1a = GUICtrlCreateRadio ("Answer 1", 10, 140, 360, 20)
$radio2a = GUICtrlCreateRadio ("Answer 2.", 10, 170, 360, 20)
$radio3 = GUICtrlCreateRadio ("Answer 3.", 10, 200, 360, 20)

GUICtrlSetState ($radio3, $GUI_UNCHECKED)

GUISetState ()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $radio1a And BitAND(GUICtrlRead($radio1a), $GUI_CHECKED) = $GUI_CHECKED
            $Count = $Count + 1
            ExitLoop
        Case $msg = $radio2a And BitAND(GUICtrlRead($radio2a), $GUI_CHECKED) = $GUI_CHECKED
            ExitLoop
        Case $msg = $radio3 And BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED
        ExitLoop
    EndSelect
Wend


GUICreate("Question 2", 200, 170)

$labelb = Guictrlcreatelabel ("Question 2", 10, 10, 120, 20)
$radio1b = GUICtrlCreateRadio ("Answer 3", 10, 40, 120, 20)
$radio2b = GUICtrlCreateRadio ("Answer 2", 10, 70, 120, 20)
$radio3b = GUICtrlCreateRadio ("Answer 1", 10, 100, 120, 20)

GUICtrlSetState ($radio3b, $GUI_UNCHECKED)

GUISetState ()     

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $radio1b And BitAND(GUICtrlRead($radio1b), $GUI_CHECKED) = $GUI_CHECKED
            ExitLoop
        Case $msg = $radio2b And BitAND(GUICtrlRead($radio2b), $GUI_CHECKED) = $GUI_CHECKED
            $Count = $Count + 1
            ExitLoop
        Case $msg = $radio3b And BitAND(GUICtrlRead($radio3b), $GUI_CHECKED) = $GUI_CHECKED
            ExitLoop
    EndSelect
Wend


msgbox (0, "Total score", $Count, 10)

    $file = FileOpen("\\serverpath\results$\Test.txt", 1)
    FileWriteLine($file, @Crlf&" "&@UserName&" Ended the test with a score of "&$count)
    FileClose($file)

What it's supposed to do: You answer a question and it either adds +1 to the total count in case of a correct answer or add nothing to it. When you select the Radio the current window is supposed to close and the next question is supposed to come up. In the end it's supposed to display your total score and write it to a .txt file

What it actually does: When you select an answer the counter thingy works and the next window comes up, but the first one doesnt close. Everything else seems to work just fine.

How can I get the window to close, register the score and open the next one?

Thanks in advance.


Share this post


Link to post
Share on other sites
Kerros

Working with your existing code, you just need to place a GUISetState(@SW_Hide) and GUISetState(@SW_Show) in the appropate places. code is shown below.

#include 

$Count = 0
GUICreate("Question 1", 400, 250)
$labela = Guictrlcreatelabel ("Question here", 10, 10, 360, 120)
$radio1a = GUICtrlCreateRadio ("Answer 1", 10, 140, 360, 20)
$radio2a = GUICtrlCreateRadio ("Answer 2.", 10, 170, 360, 20)
$radio3 = GUICtrlCreateRadio ("Answer 3.", 10, 200, 360, 20)

GUICtrlSetState ($radio3, $GUI_UNCHECKED)

GUISetState ()

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $radio1a And BitAND(GUICtrlRead($radio1a), $GUI_CHECKED) = $GUI_CHECKED
            $Count = $Count + 1
            ExitLoop
        Case $msg = $radio2a And BitAND(GUICtrlRead($radio2a), $GUI_CHECKED) = $GUI_CHECKED
            ExitLoop
        Case $msg = $radio3 And BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED
        ExitLoop
    EndSelect
Wend
GUISetState(@SW_HIDE)

GUICreate("Question 2", 200, 170)

$labelb = Guictrlcreatelabel ("Question 2", 10, 10, 120, 20)
$radio1b = GUICtrlCreateRadio ("Answer 3", 10, 40, 120, 20)
$radio2b = GUICtrlCreateRadio ("Answer 2", 10, 70, 120, 20)
$radio3b = GUICtrlCreateRadio ("Answer 1", 10, 100, 120, 20)

GUICtrlSetState ($radio3b, $GUI_UNCHECKED)

GUISetState (@SW_SHOW)     

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $radio1b And BitAND(GUICtrlRead($radio1b), $GUI_CHECKED) = $GUI_CHECKED
            ExitLoop
        Case $msg = $radio2b And BitAND(GUICtrlRead($radio2b), $GUI_CHECKED) = $GUI_CHECKED
            $Count = $Count + 1
            ExitLoop
        Case $msg = $radio3b And BitAND(GUICtrlRead($radio3b), $GUI_CHECKED) = $GUI_CHECKED
            ExitLoop
    EndSelect
Wend


msgbox (0, "Total score", $Count, 10)

    $file = FileOpen("c:\Test.txt", 1)
    FileWriteLine($file, @Crlf&" "&@UserName&" Ended the test with a score of "&$count)
    FileClose($file)

Edit to use Ubound in the for next loop.

Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites
Captnplanet

Thanks for the reply.

The first one you entered seems to work perfectly but I cant seem to get the second one working.

I'll stick with the first one (since I gotta enter quite an amount of different answers/questions and I think an array will be a bit messy for that)

Thanks again!


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.