Jump to content

Checking result of a test with radios


Recommended Posts

Took me some days to figure out how checking multiple grouped radios works.

Now i would like to check the result of multiple radios.

This is what i made

Posted Image

As you can see i will select 4 radios each time the test will pop up.

Question is simple. I have to check every single radio for every group like this:

If (GUICtrlRead($radio_1)=$GUI_CHECKED) Then
            If (GUICtrlRead($Radio1,1)="Right Answer Text") Then

for every radio button, or there is a way to just check if the checked radio is containing the right text?

Ex: If Current Checked Radio Box = Right answer text then

etc etc

Thanks in advance.

Edited by niubbone
Link to comment
Share on other sites

  • Moderators

niubbone,

Use the "advanced" parameter of GUICtrlRead. :party:

I would do it something like this, using loops to shorten the code: :mellow:

#include <GUIConstantsEx.au3>

; These are the correct answers
Global $aCorrect[4] = ["a1", "b2", "c3", "d4"]

$hGUI = GUICreate("Test", 500, 500)

; Create the groups of radios in IMMEDIATE succession - do not add any other controls between them
GUIStartgroup()
$hRadio_a1 = GUICtrlCreateRadio("a1", 10, 10, 50, 20)
Opt("GUICoordMode", 0)
$hRadio_a2 = GUICtrlCreateRadio("a2", 0, 20, 50, 20)
$hRadio_a3 = GUICtrlCreateRadio("a3", 0, 20, 50, 20)
$hRadio_a4 = GUICtrlCreateRadio("a4", 0, 20, 50, 20)
GUIStartgroup()
$hRadio_b1 = GUICtrlCreateRadio("b1", 0, 40, 50, 20)
$hRadio_b2 = GUICtrlCreateRadio("b2", 0, 20, 50, 20)
$hRadio_b3 = GUICtrlCreateRadio("b3", 0, 20, 50, 20)
$hRadio_b4 = GUICtrlCreateRadio("b4", 0, 20, 50, 20)
GUIStartgroup()
$hRadio_c1 = GUICtrlCreateRadio("c1", 0, 40, 50, 20)
$hRadio_c2 = GUICtrlCreateRadio("c2", 0, 20, 50, 20)
$hRadio_c3 = GUICtrlCreateRadio("c3", 0, 20, 50, 20)
$hRadio_c4 = GUICtrlCreateRadio("c4", 0, 20, 50, 20)
GUIStartgroup()
$hRadio_d1 = GUICtrlCreateRadio("d1", 0, 40, 50, 20)
$hRadio_d2 = GUICtrlCreateRadio("d2", 0, 20, 50, 20)
$hRadio_d3 = GUICtrlCreateRadio("d3", 0, 20, 50, 20)
$hRadio_d4 = GUICtrlCreateRadio("d4", 0, 20, 50, 20)
GUIStartgroup()

$hButton = GUICtrlCreateButton("Check", 10, 40, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ; Check each group of radios in turn
            For $j = 0 To 3
                ; Calculate ControlID of first radio in group
                $iStartControlID = $hRadio_a1 + (4 * $j)
                ; Check each radio in the group
                For $i =  $iStartControlID To $iStartControlID + 3
                    ; If the radio is checked
                    If GUICtrlRead($i) = 1 Then
                        ; Check if the text for this radio matches the answer
                        If GUICtrlRead($i, 1) = $aCorrect[$j] Then ; <<<<<<<<<<<<<<<<<<<<<< Note advanced parameter set
                            ConsoleWrite("Group " & Chr($j + 97) & " Correct" & @CRLF)
                            ExitLoop
                        Else
                            ConsoleWrite("Group " & Chr($j + 97) & " Wrong" & @CRLF)
                            ExitLoop
                        EndIf
                    EndIf
                Next
                ; If no radios were checked in a group
                If $i = $iStartControlID + 4 Then ConsoleWrite("No Radio checked in Group " & Chr($j + 97) & @CRLF)
            Next
    EndSwitch

WEnd

I hope that helps you. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

You can use the fact that control ID's are assigned sequentially to allow you to scan whole groups of controls in one statement. Adding new controls within the group, without adjusting your formulas can throw everything off kilter though. Something like:

#include <GUIConstantsEx.au3>
Example()

Func Example()
    Global $Q_cnt = 4, $A_cnt = 4 ; number of questions, number of answers per question
    Global $radio[$Q_cnt + 1][$A_cnt + 1]
    GUICreate("", 200, $Q_cnt * 40  + $Q_cnt * $A_cnt * 20 + 40)

    $top = 10
    For $x = 1 to $Q_cnt
        GUICtrlCreateLabel("Question " & $x, 10, $top, 120, 20)
        For $y = 1 to $A_cnt
            $top += 20
            $radio[$x][$y] = GUICtrlCreateRadio("Answer " & $y, 20, $top, 120, 20)
        Next
        $top += 40
    Next
    GUICtrlCreateLabel("Result: ", 10, $top, 60, 20)
    $R = GUICtrlCreateLabel("", 60, $top, 120, 20)
    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case -3
                ExitLoop
            Case $radio[1][1] to $radio[$Q_cnt][$A_cnt]
                $x = $msg - ($radio[1][1] - 1)
                $Q = Int($x / ($A_cnt + 1)) + 1
                $A = Mod($x, $A_cnt + 1)
                Beep(800,50)
                GUICtrlSetData($R, "Q = " & $Q & ", A = " & $A)
        EndSwitch
    WEnd
EndFunc

Edit: typo

Edited by Spiff59
Link to comment
Share on other sites

Ok, a more complete demo...

#include <GUIConstantsEx.au3>

Global $Q_cnt = 3, $A_cnt = 4 ; number of questions, number of answers per question
Global $radio[$Q_cnt + 1][$A_cnt + 1], $score, $score_label
Global $table[$Q_cnt + 1][$A_cnt + 2] = [["","","","",0], _
        ["Who's on first?", "Abbott", "Costello", "Wright", "Nobody", 3], _
        ["Who's in Grants tomb?", "Abbott", "Costello", "Nobody", "Grant", 4], _
        ["What is the meaning of life?", "42", "I dunno", "Nobody", "Mikey likes it", 1]]

Example()

Func Example()
    GUICreate("", 300, $Q_cnt * 40  + $Q_cnt * $A_cnt * 20 + 40)
    $top = 10
    For $x = 1 to $Q_cnt
        GUIStartGroup()
        GUICtrlCreateLabel($table[$x][0], 10, $top, 200, 20)
        For $y = 1 to $A_cnt
            $top += 20
            $radio[$x][$y] = GUICtrlCreateRadio($table[$x][$y], 20, $top, 120, 20)
        Next
        $top += 40
    Next
    GUICtrlCreateLabel("Score: ", 10, $top, 60, 20)
    $score_label = GUICtrlCreateLabel("", 60, $top, 120, 20)
    GUISetState()

;===============================================================================
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case -3
                ExitLoop
            Case $radio[1][1] to $radio[$Q_cnt][$A_cnt]
;               $x = $msg - ($radio[1][1] - 1)
;               $Q = Int($x / ($A_cnt + 1)) + 1
;               $A = Mod($x, $A_cnt + 1)
;               Beep(800,50)
;               ToolTip("Q = " & $Q & ", A = " & $A)
                Score()
        EndSwitch
    WEnd
EndFunc
Func Score()
    $score = 0
    For $x = 1 to $Q_cnt
        $y = $table[$x][$a_cnt + 1]
        If GUICtrlRead($radio[$x][$y]) = $GUI_CHECKED Then $score += 1
    Next
    GUICtrlSetData($score_label, $score)
EndFunc

Edit: commented out the "fluff"

Edited by Spiff59
Link to comment
Share on other sites

Thanks for your time guys.

Melba23

I used Advanced setting in my code ;P look at it xD

Btw

I don't fully understand your code.

Case $hButton
            ; Check each group of radios in turn
            For $j = 0 To 3
                ; Calculate ControlID of first radio in group
                $iStartControlID = $hRadio_a1 + (4 * $j);what this does? How you switch from a group to another? Don't get the idea behind this
                ; Check each radio in the group
                For $i =  $iStartControlID To $iStartControlID + 3
                    ; If the radio is checked
                    If GUICtrlRead($i) = 1 Then
                        ; Check if the text for this radio matches the answer
                        If GUICtrlRead($i, 1) = $aCorrect[$j] Then ;

I don't get the point behind this

$iStartControlID = $hRadio_a1 + (4 * $j)

If i got it right this is what you are doing.

Initialize a $j counter from 0 to 3,

With $iStartControlID You initialize a counter which as you say calculates the controlIDs but I don't get how it does it,

The following For statement make the IDs add 4 each time to control them with the if statements like this Id=5 then 6,7,8 and so on till 16;

Then If Radio with control ID $i is 1 (CHECKED) then control it;

Here another point I have a doubt on. If GUICtrlRead($i, 1) = $aCorrect[$j] Then

Here, the code would work only if the question for the test are only the same 4 everytime right? but this test is going to be repeated many times and I am planning to make question picked randomly from an array of over 50 questions.

So there will be not only question A with replies A1 A2 A3 A4, B with B1 B2 B3 B4, but there will be also many more possibilities, like R with R1 R2 R3 R4, and so on because there will be much questions. Am i right? There is a way to make it work with multiple randomly picked questions?

Spiff59

Posted Image

I don't even know where to start... way too much complicated for me...

Sorry but I think it would take me a month to understand it....

Thanks anyway....

Any further explanation would be appreciated

Link to comment
Share on other sites

  • Moderators

niubbone,

OK, one step at a time. :P

I don't get the point behind this - $iStartControlID = $hRadio_a1 + (4 * $j)

ControlIDs (how AutoIt knows which control you are refering to) are allocated in numerical succession - that is why I mentioned that you must NOT put any other controls in the list. When I run this code, the ControlIDs for the radios are as follows:

a1 - 3
a2 - 4
a3 - 5
a4 - 6
b1 - 7
b2 - 8
b3 - 9
b4 - 10
c1 - 11
...
d1 - 15
etc

You have 4 blocks of radios - we are going to check all 4 by using a loop running from 0 to 3. You can easily calculate the ControlID of the first radio in each block by making the calculation:

$iStartControlID = $hRadio_a1 + (4 * $j)

We will start each loop at this first radio which will advance by 4 each time we go through the loop. Because the radios have successive ControlIDs, we just add 4, 8, 12 to the ControlID of the first radio by using the (4 * $j) element.

Then If Radio with control ID $i is 1 (CHECKED) then control it;

Correct. :party:

GUICtrlRead($i, 1) = $aCorrect[$j] Then

Here, the code would work only if the question for the test are only the same 4 everytime right?

Also correct. But I was not going to write the whole code for you! :mellow:

There is a way to make it work with multiple randomly picked questions?

You must have some code which selects the 4 random questions to ask - there will be 1 correct and 3 wrong answers attached to each of these questions, so you need to make your own array containing the 4 correct answers each time you initialise the GUI.

Does that make it clearer? :party:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Spiff59

I don't even know where to start... way too much complicated for me...

And I thought mine was the more straight-forward example! lol

I suppose me making it an auto-sized GUI that self-adjusts to a variable number of questions and question options did add some complexity. And the formula to display the tooltip (all of which I'd commented out) may appear a little scary.

Were it my beast, I'd likely load the question-count and option-count variables, as well as the actual $table array (questions, options, and correct answer), from a text file. Maybe even put a "test title" in the text file, and make the script read a command-line parameter to point it to a particular text file. Then you could use the same script for multiple tests, and change the number of questions, or change the questions themselves anytime without any changes to, or recompile of, your script. The more that is hard-coded, the more difficult it is to modify down the road. Maybe even add a randomizer to mix the answers beneath a question, or mix the questions within a test. Hmm, maybe section titles, T/F question types... lol, this could balloon into a full-fledged application. I bet someone has already done one?

If the array/table portion of my example is confusing... then you NEED to brush up on that stuff! Well organized data can save a ton of coding. Indexing/Subscripting is a HUGELY powerful tool.

Edit: Here it is with less bells-and-whistles:

#include <GUIConstantsEx.au3>

Global $radio[3][5], $score, $score_label
Global $table[3][6] = [ _
        ["Who's on first?", "Abbott", "Costello", "Wright", "Nobody", 3], _
        ["Who's in Grants tomb?", "Abbott", "Costello", "Nobody", "Grant", 4], _
        ["What is the meaning of life?", "42", "I dunno", "Nobody", "Mikey likes it", 1]]

;===============================================================================
GUICreate("", 300, 460)
GUICtrlCreateLabel("THE MENSA TEST", 100, 20, 120, 20)
$top = 60 ; vertical screen position
For $x = 0 to 2 ; create a 3 x 4 table of radio buttons
    GUIStartGroup()
    GUICtrlCreateLabel($table[$x][0], 10, $top, 200, 20)
    $top += 20
    For $y = 1 to 4
        $radio[$x][$y] = GUICtrlCreateRadio($table[$x][$y], 20, $top, 120, 20)
        $top += 20
    Next
    $top += 20
Next
$top += 20
GUICtrlCreateLabel("Score: ", 10, $top, 60, 20)
$score_label = GUICtrlCreateLabel("", 60, $top, 120, 20)
GUISetState()

;===============================================================================
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            ExitLoop
        Case $radio[0][1] to $radio[2][4] ; was any radio button clicked?
            Score() ; recalc score
     EndSwitch
WEnd

Func Score()
    $score = 0
    For $x = 0 to 2
        $y = $table[$x][5] ; the correct answer for question $x
        If GUICtrlRead($radio[$x][$y]) = $GUI_CHECKED Then $score += 1
    Next
    GUICtrlSetData($score_label, $score)
EndFunc
Edited by Spiff59
Link to comment
Share on other sites

Heres another example of the numerous ways of doing it.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $aQuestions[5][4] ; [questionN0][Question, Delimitered Answers, CorrectAnsPos, Correct ControlID]
$aQuestions[0][0] = 4 ; No of Questions

$aQuestions[1][0] = "What is the first letter of the alphabet."
$aQuestions[1][1] = "S|R|A|U"
$aQuestions[1][2] = 3

$aQuestions[2][0] = "What is the last letter of the alphabet."
$aQuestions[2][1] = "Z|W|L|X"
$aQuestions[2][2] = 1

$aQuestions[3][0] = "What noise does a cow make."
$aQuestions[3][1] = "Bark|oink|Meow|Moo"
$aQuestions[3][2] = 4

$aQuestions[4][0] = "Which of the following is the odd one out."
$aQuestions[4][1] = "Pencil|Banana|Pen|PaintBrush"
$aQuestions[4][2] = 2


$Form1 = GUICreate("Questions", 300, 500, -1, -1)
$itop = 10
For $i = 1 To $aQuestions[0][0]
    GUICtrlCreateLabel($i & ")  " & $aQuestions[$i][0], 10, $itop)
    $aAnswers = StringSplit($aQuestions[$i][1], "|") ; split Answers into an array
    GUIStartGroup()
    For $iAns = 1 To $aAnswers[0] ;Loop through Answers
        $itop += 20
        $hControlID = GUICtrlCreateRadio(Chr(96 + $iAns) & ".   " & $aAnswers[$iAns] & " .   ", 10, $itop) ;Temp store controlID
        If $iAns = $aQuestions[$i][2] Then $aQuestions[$i][3] = $hControlID ; Only Store correct controlID into Questions Array
    Next
    $itop += 30
Next
$itop += 10
$hButtonCheckAns = GUICtrlCreateButton("Check Answers", 10, $itop)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButtonCheckAns
            $sOutput = "Your answers are as follows:" & @CR
            For $i = 1 To $aQuestions[0][0] Step 1
                $sOutput &= @CR & $i & ") "
                If GUICtrlRead($aQuestions[$i][3]) = $GUI_CHECKED Then ; Read correct ControlID
                    $sOutput &= " is Correct"
                Else
                    $sOutput &= " is Wrong"
                EndIf
            Next
            MsgBox(0, "How well did you do ?", $sOutput)

    EndSwitch
WEnd

Edit > here is a static easy to follow version with no arrays, loops ect.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 264, 540, 192, 124)
GUICtrlCreateLabel("1) What is the first letter of the alphabet.", 8, 8, 192, 17)
GUIStartGroup()
GUICtrlCreateRadio("a.  S", 24, 32, 113, 17)
GUICtrlCreateRadio("b.  R", 24, 56, 113, 17)
$hAnswer1Correct = GUICtrlCreateRadio("c.  A", 24, 80, 113, 17)
GUICtrlCreateRadio("d.  U", 24, 104, 113, 17)
GUICtrlCreateLabel("2) What is the last letter of the alphabet.", 8, 136, 192, 17)
GUIStartGroup()
$hAnswer2Correct = GUICtrlCreateRadio("a.  Z", 24, 160, 113, 17)
GUICtrlCreateRadio("b.  W", 24, 184, 113, 17)
GUICtrlCreateRadio("c.  L", 24, 208, 113, 17)
GUICtrlCreateRadio("d.  X", 24, 232, 113, 17)
GUICtrlCreateLabel("3) What noise does a cow make", 8, 256, 157, 17)
GUIStartGroup()
GUICtrlCreateRadio("a.  Bark", 24, 280, 113, 17)
GUICtrlCreateRadio("b.  Oink", 24, 304, 113, 17)
GUICtrlCreateRadio("c.  Meow", 24, 328, 113, 17)
$hAnswer3Correct = GUICtrlCreateRadio("d.  Moo", 24, 352, 113, 17)
GUICtrlCreateLabel("4) Which of the following is the odd one out", 8, 384, 209, 17)
GUIStartGroup()
GUICtrlCreateRadio("a.  Pencil", 24, 408, 113, 17)
$hAnswer4Correct = GUICtrlCreateRadio("b.  Banana", 24, 432, 113, 17)
GUICtrlCreateRadio("c.  Pen", 24, 456, 113, 17)
GUICtrlCreateRadio("d.  Paintbrush", 24, 480, 113, 17)
$Button1 = GUICtrlCreateButton("Check Answer", 16, 512, 91, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $sOutput = "Your answers are as follows:" & @CR & @CR
            If GUICtrlRead($hAnswer1Correct) = $GUI_CHECKED Then
                $sOutput &= "1. is Correct" & @CR
            Else
                $sOutput &= "1. is Wrong" & @CR
            EndIf
            If GUICtrlRead($hAnswer2Correct) = $GUI_CHECKED Then
                $sOutput &= "2. is Correct" & @CR
            Else
                $sOutput &= "2. is Wrong" & @CR
            EndIf
            If GUICtrlRead($hAnswer3Correct) = $GUI_CHECKED Then
                $sOutput &= "3. is Correct" & @CR
            Else
                $sOutput &= "3. is Wrong" & @CR
            EndIf
            If GUICtrlRead($hAnswer4Correct) = $GUI_CHECKED Then
                $sOutput &= "4. is Correct" & @CR
            Else
                $sOutput &= "4. is Wrong" & @CR
            EndIf
            MsgBox(0, "How well did you do ?", $sOutput)

    EndSwitch
WEnd
Edited by Yoriz
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Thanks to all for the HUGE help.

Thanks to Melba23 for explaining his code. Needed it.

Thanks to Yoriz Which gave me 2 versions. The first allowed me to better understand Spiff59 "method of coding", The second fitted more my problem, and also if doesnt solve it, it gave me a great input to solve it myself.

Thanks to Spiff59, as now I start getting (still have to work on it) the concept behind his code, and looks pretty good.

Great work guys, When I solve it I'll post the code.

One more question: How autoit assigns control IDs?

I have always seen that radios control id never starts from 1 or so. Sometimes starts from 2 sometimes from 5 and so on. What is counted first?

As you see in Melba23 Code:

a1 - 3

a2 - 4

a3 - 5

a4 - 6

b1 - 7

b2 - 8

b3 - 9

b4 - 10

c1 - 11

The first radio starts with 3.... but before there aren't any gui elements....

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Local $GUITestLavoro = GUICreate("Test Colloquio Lavorativo", 468, 643, 402, 7)
                            GUICtrlCreateLabel("TEST DI IDONEITA' AL POSTO DI LAVORO", 48, 16, 377, 28)
                            GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
                            GUICtrlCreateLabel("Mi raccomando, non faccia il coglione come al suo solito....", 104, 56, 282, 17)
                            GUICtrlCreateLabel("1)", 8, 88, 17, 22)
                            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            GUIStartGroup()
                            Local $LabelRadioDom1 = GUICtrlCreateLabel("dom1", 32, 88, 30, 17)
                            Local $Radio1 = GUICtrlCreateRadio("Radio1", 8, 112, 425, 17)
                            Local $Radio2 = GUICtrlCreateRadio("Radio2", 8, 136, 425, 17)
                            Local $Radio3 = GUICtrlCreateRadio("Radio3", 8, 160, 425, 17)
                            Local $Radio4 = GUICtrlCreateRadio("Radio4", 8, 184, 425, 17)
                            GUICtrlCreateLabel("2)", 12, 211, 17, 20)
                            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            GUIStartGroup()
                            Local $LabelRadioDom2 = GUICtrlCreateLabel("dom2", 36, 211, 30, 17)
                            Local $Radio5 = GUICtrlCreateRadio("Radio1b", 12, 235, 425, 17)
                            Local $Radio6 = GUICtrlCreateRadio("Radio2b", 12, 259, 425, 17)
                            Local $Radio7 = GUICtrlCreateRadio("Radio3b", 12, 283, 425, 17)
                            Local $Radio8 = GUICtrlCreateRadio("Radio4b", 12, 307, 425, 17)
                            GUICtrlCreateLabel("3)", 12, 340, 17, 20)
                            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            GUIStartGroup()
                            Local $LabelRadioDom3 = GUICtrlCreateLabel("dom3", 36, 340, 30, 17)
                            Local $Radio9 = GUICtrlCreateRadio("Radio1c", 12, 364, 425, 17)
                            Local $Radio10 = GUICtrlCreateRadio("Radio2c", 12, 388, 425, 17)
                            Local $Radio11 = GUICtrlCreateRadio("Radio3c", 12, 412, 425, 17)
                            Local $Radio12 = GUICtrlCreateRadio("Radio4c", 12, 436, 425, 17)
                            GUICtrlCreateLabel("4)", 12, 462, 17, 20)
                            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            GUIStartGroup()
                            Local $LabelRadioDom4 = GUICtrlCreateLabel("dom4", 36, 462, 30, 17)
                            Local $Radio13 = GUICtrlCreateRadio("Radio1d", 12, 486, 425, 17)
                            Local $Radio14 = GUICtrlCreateRadio("Radio2d", 12, 510, 425, 17)
                            Local $Radio15 = GUICtrlCreateRadio("Radio3d", 12, 534, 425, 17)
                            Local $Radio16 = GUICtrlCreateRadio("Radio4d", 12, 558, 425, 17)
                            Local $BottoneScappaTest = GUICtrlCreateButton("Scappa....", 8, 592, 177, 41, $WS_GROUP)
                            Local $BottoneConsegnaTest = GUICtrlCreateButton("Consegna il test", 280, 592, 177, 41, $WS_GROUP)
                            Local $CompilaTest = ColloquioDomande()
                            GUICtrlSetData($LabelRadioDom1, $CompilaTest[0][0])
                            GUICtrlSetData($LabelRadioDom2, $CompilaTest[0][1])
                            GUICtrlSetData($LabelRadioDom3, $CompilaTest[0][2])
                            GUICtrlSetData($LabelRadioDom4, $CompilaTest[0][3])
                            GUICtrlSetData($Radio1, $CompilaTest[1][0])
                            GUICtrlSetData($Radio2, $CompilaTest[1][1])
                            GUICtrlSetData($Radio3, $CompilaTest[1][2])
                            GUICtrlSetData($Radio4, $CompilaTest[1][3])
                            GUICtrlSetData($Radio5, $CompilaTest[1][4])
                            GUICtrlSetData($Radio6, $CompilaTest[1][5])
                            GUICtrlSetData($Radio7, $CompilaTest[1][6])
                            GUICtrlSetData($Radio8, $CompilaTest[1][7])
                            GUICtrlSetData($Radio9, $CompilaTest[1][8])
                            GUICtrlSetData($Radio10, $CompilaTest[1][9])
                            GUICtrlSetData($Radio11, $CompilaTest[1][10])
                            GUICtrlSetData($Radio12, $CompilaTest[1][11])
                            GUICtrlSetData($Radio13, $CompilaTest[1][12])
                            GUICtrlSetData($Radio14, $CompilaTest[1][13])
                            GUICtrlSetData($Radio15, $CompilaTest[1][14])
                            GUICtrlSetData($Radio16, $CompilaTest[1][15])
                            GUISetState(@SW_SHOW)
                            For $i=$Radio1 To $Radio16
                            MsgBox(0,"i",$i)
                            Next
                            While 1
                                $nMsg = GUIGetMsg()
                                Switch $nMsg
                                    Case $GUI_EVENT_CLOSE
                                        ExitLoop
                                    Case $BottoneScappaTest
                                        ExitLoop

                                EndSwitch
                            WEnd
                            Func ColloquioDomande()
    Local $DomandaA[5] = ["domA", "a1", "a2", "a3", "a4"], $DomandaB[5] = ["domB", "b1", "b2", "b3", "b4"], $DomandaC[5] = ["domC", "c1", "c2", "c3", "c4"] _
            , $DomandaD[5] = ["domD", "d1", "d2", "d3", "d4"], $DomandaE[5] = ["domE", "e1", "e2", "e3", "e4"]
    Local $aArrays[5] = [$DomandaA, $DomandaB, $DomandaC, $DomandaD, $DomandaE]
    _ArrayShuffle($aArrays)

    Local $MultiDomERisp[2][16], $aTemp, $num = 0
    For $iArrNo = 0 To 3
        $aTemp = $aArrays[$iArrNo]
        _ArrayShuffle($aTemp, 1)
        $MultiDomERisp[0][$iArrNo] = $aTemp[0]
        For $x = 1 To UBound($aTemp) - 1
            $MultiDomERisp[1][$num] = $aTemp[$x]
            $num += 1
        Next
    Next
    Return $MultiDomERisp
EndFunc ;==>ColloquioDomande

; http://www.autoitscript.com/forum/index.php?s=&showtopic=79564&view=findpost&p=573531
Func _ArrayShuffle(ByRef $aArray, $iBase = 0, $iUBound = Default)
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    If UBound($aArray, 0) <> 1 Then Return SetError(2, 0, 0)

    Local $temp, $rand
    If $iUBound = Default Or $iUBound = 0 Then $iUBound = UBound($aArray) - 1
    For $i = $iBase To $iUBound
        $temp = $aArray[$i]
        $rand = Random($iBase, $iUBound, 1)
        $aArray[$i] = $aArray[$rand]
        $aArray[$rand] = $temp
    Next
EndFunc ;==>_ArrayShuffle

Example, this code. They start from 7 and number is even greater than Radio controls. Don't get it...

PS: Run it. I Included a msgbox that shows control ID from Radio1 to Radio16.

Edited by niubbone
Link to comment
Share on other sites

  • Moderators

niubbone,

Everything in Windows is assigned a unique handle when it is created - whether it be a window, a control an open file..... This handle is in a special format which looks a bit like Hex - 0x00070A3E for example - not too easy to work with. :party:

AutoIt makes life easy for you by assigning every control a ControlID rather than using the actual handle that Windows assigns it. AutoIt maintains these controlIDs in an internal array with 65532 elements - that is why there is a limit of 65532 controls in a single script. :party:

Autoit has its own hidden window which is always present - I imagine that is where the first few elements of this array (and hence the first few ControlIds are used) - so your first control always has the ControlID of 3.

AutoIt allocates the ControlIDs in strict numerical order, as you have seen. But beware, if you delete a control there is now an empty element in the array and AutoIt will fill that gap before looking to the next number in numerical sequence - like this:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hLabel_1 = GUICtrlCreateLabel("", 10, 10)
ConsoleWrite("I am control 1 with ControlID = " & $hLabel_1 & @CRLF)
$hLabel_2 = GUICtrlCreateLabel("", 10, 10)
ConsoleWrite("I am control 2 with ControlID = " & $hLabel_2 & @CRLF)
$hLabel_3 = GUICtrlCreateLabel("", 10, 10)
ConsoleWrite("I am control 3 with ControlID = " & $hLabel_3 & @CRLF)

; Now delete the second control
GUICtrlDelete($hLabel_2)

$hLabel_4 = GUICtrlCreateLabel("", 10, 10)
ConsoleWrite("I am control 4 with ControlID = " & $hLabel_4 & @CRLF)

; See the ControlID is 4, not 6 as you might expect

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

We can use the ControlIds of controls created in IMMEDIATE succession to run loops as in the code I posted above - but you must make sure there are no intermediate controls and that there have been no controls deleted previously. If either of these conditions are not met - you will not get successive ControlIds and the trick will not work. :P

All clear? :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Posting anyway as i got beaten to it but spent time on it :mellow:

Changed your code a bit and made some new msgboxes to explain things a bit.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Local $GUITestLavoro = GUICreate("Test Colloquio Lavorativo", 468, 643, 402, 7)
                            $hFirstControlcreated = GUICtrlCreateLabel("TEST DI IDONEITA' AL POSTO DI LAVORO", 48, 16, 377, 28)
                            GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
                            GUICtrlCreateLabel("Mi raccomando, non faccia il coglione come al suo solito....", 104, 56, 282, 17)
                            $hThirdControlcreated = GUICtrlCreateLabel("1)", 8, 88, 17, 22)
                            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            GUIStartGroup()
                            Local $LabelRadioDom1 = GUICtrlCreateLabel("dom1", 32, 88, 30, 17)
                            Local $Radio1 = GUICtrlCreateRadio("Radio1", 8, 112, 425, 17)
                            Local $Radio2 = GUICtrlCreateRadio("Radio2", 8, 136, 425, 17)
                            Local $Radio3 = GUICtrlCreateRadio("Radio3", 8, 160, 425, 17)
                            Local $Radio4 = GUICtrlCreateRadio("Radio4", 8, 184, 425, 17)
;~                             GUICtrlCreateLabel("2)", 12, 211, 17, 20)
;~                             GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            GUIStartGroup()
;~                             Local $LabelRadioDom2 = GUICtrlCreateLabel("dom2", 36, 211, 30, 17)
                            Local $Radio5 = GUICtrlCreateRadio("Radio1b", 12, 235, 425, 17)
                            Local $Radio6 = GUICtrlCreateRadio("Radio2b", 12, 259, 425, 17)
                            Local $Radio7 = GUICtrlCreateRadio("Radio3b", 12, 283, 425, 17)
                            Local $Radio8 = GUICtrlCreateRadio("Radio4b", 12, 307, 425, 17)
;~                             GUICtrlCreateLabel("3)", 12, 340, 17, 20)
;~                             GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            GUIStartGroup()
;~                             Local $LabelRadioDom3 = GUICtrlCreateLabel("dom3", 36, 340, 30, 17)
                            Local $Radio9 = GUICtrlCreateRadio("Radio1c", 12, 364, 425, 17)
                            Local $Radio10 = GUICtrlCreateRadio("Radio2c", 12, 388, 425, 17)
                            Local $Radio11 = GUICtrlCreateRadio("Radio3c", 12, 412, 425, 17)
                            Local $Radio12 = GUICtrlCreateRadio("Radio4c", 12, 436, 425, 17)
;~                             GUICtrlCreateLabel("4)", 12, 462, 17, 20)
;~                             GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            GUIStartGroup()
;~                             Local $LabelRadioDom4 = GUICtrlCreateLabel("dom4", 36, 462, 30, 17)
                            Local $Radio13 = GUICtrlCreateRadio("Radio1d", 12, 486, 425, 17)
                            Local $Radio14 = GUICtrlCreateRadio("Radio2d", 12, 510, 425, 17)
                            Local $Radio15 = GUICtrlCreateRadio("Radio3d", 12, 534, 425, 17)
                            Local $Radio16 = GUICtrlCreateRadio("Radio4d", 12, 558, 425, 17)

                            ; Labels below copied version of the commeted out ones above
                            Local $LabelRadioDom2 = GUICtrlCreateLabel("dom2", 36, 211, 30, 17)
                            GUICtrlCreateLabel("2)", 12, 211, 17, 20)
                            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            GUICtrlCreateLabel("3)", 12, 340, 17, 20)
                            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            Local $LabelRadioDom3 = GUICtrlCreateLabel("dom3", 36, 340, 30, 17)
                            GUICtrlCreateLabel("4)", 12, 462, 17, 20)
                            GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                            Local $LabelRadioDom4 = GUICtrlCreateLabel("dom4", 36, 462, 30, 17)
                            ; End of copied lables

                            Local $BottoneScappaTest = GUICtrlCreateButton("Scappa....", 8, 592, 177, 41, $WS_GROUP)
                            Local $BottoneConsegnaTest = GUICtrlCreateButton("Consegna il test", 280, 592, 177, 41, $WS_GROUP)
                            Local $CompilaTest = ColloquioDomande()
                            GUICtrlSetData($LabelRadioDom1, $CompilaTest[0][0])
                            GUICtrlSetData($LabelRadioDom2, $CompilaTest[0][1])
                            GUICtrlSetData($LabelRadioDom3, $CompilaTest[0][2])
                            GUICtrlSetData($LabelRadioDom4, $CompilaTest[0][3])
                            GUICtrlSetData($Radio1, $CompilaTest[1][0])
                            GUICtrlSetData($Radio2, $CompilaTest[1][1])
                            GUICtrlSetData($Radio3, $CompilaTest[1][2])
                            GUICtrlSetData($Radio4, $CompilaTest[1][3])
                            GUICtrlSetData($Radio5, $CompilaTest[1][4])
                            GUICtrlSetData($Radio6, $CompilaTest[1][5])
                            GUICtrlSetData($Radio7, $CompilaTest[1][6])
                            GUICtrlSetData($Radio8, $CompilaTest[1][7])
                            GUICtrlSetData($Radio9, $CompilaTest[1][8])
                            GUICtrlSetData($Radio10, $CompilaTest[1][9])
                            GUICtrlSetData($Radio11, $CompilaTest[1][10])
                            GUICtrlSetData($Radio12, $CompilaTest[1][11])
                            GUICtrlSetData($Radio13, $CompilaTest[1][12])
                            GUICtrlSetData($Radio14, $CompilaTest[1][13])
                            GUICtrlSetData($Radio15, $CompilaTest[1][14])
                            GUICtrlSetData($Radio16, $CompilaTest[1][15])
                            GUISetState(@SW_SHOW)
                            MsgBox(0, "", "Autoit assigns numbers to controls that are created to keep track of them" & @CR & _
                                          "Note there isnt a seperate index depending on which type of control they are")
                            MsgBox(0, "ControlID of the first controlcreated", "$hFirstControlcreated: " & $hFirstControlcreated & @CR & _
                                      "The third control created must have an id of $hFirstControlcreated+2 lets check" & @CR & _
                                      "$hFirstControlcreated+2 = " & $hFirstControlcreated+2 & @CR & _
                                      "and the actual value of $hThirdControlcreated = " & $hThirdControlcreated)

                            $sText = ""
                            For $i=$Radio1 To $Radio16
                                $sText &= "|" & $i
                            Next
                            MsgBox(0,"i",$sText & @CR & "This list of controlid is all that where created between $Radio1 & $Radio16" & @CR & _
                                "You were creating labels in between creating radios so there ids where included i've commeted out the original labels" & @CR & _
                                "and made a copy of them after the radios are created and youll see that now it just the radio controlids")
                                MsgBox(0,"Total amount of controls created is 28", "The last control created is the button with contrlid stored in $BottoneConsegnaTest" & @CR & _
                                         "even tho we never stored the value of some of the controlids the last control id will be" & @CR & _
                                         "$hFirstControlcreated+27 = " & $hFirstControlcreated+27 & " and the actual controlid of $BottoneConsegnaTest = " & $BottoneConsegnaTest)
                            MsgBox(0, "Test", "The control id of of the label that has the text '3)' was not stored in a variable" & @CR & _
                                      "$LabelRadioDom2 was created 2 before it so lets try this. GUICtrlRead($LabelRadioDom2+2)" & @CR & _
                                      GUICtrlRead($LabelRadioDom2+2) & " is the text of that label created 2 after $LabelRadioDom2")
                            While 1
                                $nMsg = GUIGetMsg()
                                Switch $nMsg
                                    Case $GUI_EVENT_CLOSE
                                        ExitLoop
                                    Case $BottoneScappaTest
                                        ExitLoop

                                EndSwitch
                            WEnd
                            Func ColloquioDomande()
    Local $DomandaA[5] = ["domA", "a1", "a2", "a3", "a4"], $DomandaB[5] = ["domB", "b1", "b2", "b3", "b4"], $DomandaC[5] = ["domC", "c1", "c2", "c3", "c4"] _
            , $DomandaD[5] = ["domD", "d1", "d2", "d3", "d4"], $DomandaE[5] = ["domE", "e1", "e2", "e3", "e4"]
    Local $aArrays[5] = [$DomandaA, $DomandaB, $DomandaC, $DomandaD, $DomandaE]
    _ArrayShuffle($aArrays)

    Local $MultiDomERisp[2][16], $aTemp, $num = 0
    For $iArrNo = 0 To 3
        $aTemp = $aArrays[$iArrNo]
        _ArrayShuffle($aTemp, 1)
        $MultiDomERisp[0][$iArrNo] = $aTemp[0]
        For $x = 1 To UBound($aTemp) - 1
            $MultiDomERisp[1][$num] = $aTemp[$x]
            $num += 1
        Next
    Next
    Return $MultiDomERisp
EndFunc ;==>ColloquioDomande

; http://www.autoitscript.com/forum/index.php?s=&showtopic=79564&view=findpost&p=573531
Func _ArrayShuffle(ByRef $aArray, $iBase = 0, $iUBound = Default)
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    If UBound($aArray, 0) <> 1 Then Return SetError(2, 0, 0)

    Local $temp, $rand
    If $iUBound = Default Or $iUBound = 0 Then $iUBound = UBound($aArray) - 1
    For $i = $iBase To $iUBound
        $temp = $aArray[$i]
        $rand = Random($iBase, $iUBound, 1)
        $aArray[$i] = $aArray[$rand]
        $aArray[$rand] = $temp
    Next
EndFunc ;==>_ArrayShuffle
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

  • Moderators

Yoriz,

But yours is much nicer - all interactive! :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba23,

I'm just an amature compared, yours is nice and informative :mellow: and it has lots of Smileys :P

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
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...