Jump to content

Test Generator. Problem making random questions.


Recommended Posts

Much easier to explain if u copy this and run it in scite.

As you can see i made a gui with different grouped radios which represent a test with 4 questions with 4 answers each. The code randomize the selection of questions and scramble the answers for each question (each question has it's own answers Example: Question A asnwers are a1,a2,a3,a4 and so on).

The problem? Try to run it few times and see yourself. Some answers aren't randomized properly, in fact, the corrispondence is violated, and you see some questions with replies which should not be there. For example I get Question D with replies c1,c2 and so on when it should be d1,d2. Tried to run it tons of times to see a logic behind that error but found nothing. Also made various attempts to correct it but i came up with nothing. Someone more experienced see where's the error is? It's 2 days i'm behind this... Thanks

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.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("WorkTest", 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)
                                While 1
                                    $nMsg = GUIGetMsg()
                                    Switch $nMsg
                                        Case $GUI_EVENT_CLOSE
                                            ExitLoop
                                        Case $BottoneScappaTest
                                            Exitloop

                                    EndSwitch
                                WEnd
Func ColloquioDomande()
    Local $Domande[5]=["doma","domb","domc","domd","dome"]
    Local $Risposte[20]=["a1","a2","a3","a4","b1","b2","b3","b4","c1","c2","c3","c4","d1","d2","d3","d4","e1","e2","e3","e4"]
    Local $DomandeDifferenti[4]
    Local $RisposteMischiate[16]
    Local $i=1
    Local $r=4
    For $z=1 To 4
        Local $GiroDomande=Random(1,Ubound($Domande)-1,1)
        $DomandeDifferenti[$z-1]=$Domande[$GiroDomande]
        _ArrayDelete($Domande,$GiroDomande)
        Select
            Case $GiroDomande=0
                Local $Risp1=$Risposte[0],$Risp2=$Risposte[1],$Risp3=$Risposte[2],$Risp4=$Risposte[3]
                Local $RisposteInOrdine[4]=[$Risp1,$Risp2,$Risp3,$Risp4]
            Case $GiroDomande=1
                Local $Risp1=$Risposte[4],$Risp2=$Risposte[5],$Risp3=$Risposte[6],$Risp4=$Risposte[7]
                Local $RisposteInOrdine[4]=[$Risp1,$Risp2,$Risp3,$Risp4]
            Case $GiroDomande=2
                Local $Risp1=$Risposte[8],$Risp2=$Risposte[9],$Risp3=$Risposte[10],$Risp4=$Risposte[11]
                Local $RisposteInOrdine[4]=[$Risp1,$Risp2,$Risp3,$Risp4]
            Case $GiroDomande=3
                Local $Risp1=$Risposte[12],$Risp2=$Risposte[13],$Risp3=$Risposte[14],$Risp4=$Risposte[15]
                Local $RisposteInOrdine[4]=[$Risp1,$Risp2,$Risp3,$Risp4]
            Case $GiroDomande=4
                Local $Risp1=$Risposte[16],$Risp2=$Risposte[17],$Risp3=$Risposte[18],$Risp4=$Risposte[19]
                Local $RisposteInOrdine[4]=[$Risp1,$Risp2,$Risp3,$Risp4]
        EndSelect
        For $k=$i To $r
            Local $GiroRispInOrdine=Random(1,Ubound($RisposteInOrdine)-1,1)
            $RisposteMischiate[$k-1]=$RisposteInOrdine[$GiroRispInOrdine]
            _ArrayDelete($RisposteInOrdine,$GiroRispInOrdine)
        Next
        $i+=4
        $r+=4
    Next
    Local $MultiDomERisp[2][16]=[[$DomandeDifferenti[0],$DomandeDifferenti[1],$DomandeDifferenti[2],$DomandeDifferenti[3]], _
    [$RisposteMischiate[0],$RisposteMischiate[1],$RisposteMischiate[2],$RisposteMischiate[3],$RisposteMischiate[4], _
    $RisposteMischiate[5],$RisposteMischiate[6],$RisposteMischiate[7],$RisposteMischiate[8],$RisposteMischiate[9], _
    $RisposteMischiate[10],$RisposteMischiate[11],$RisposteMischiate[12],$RisposteMischiate[13],$RisposteMischiate[14], _
    $RisposteMischiate[15]]]
    Return $MultiDomERisp
EndFunc
Edited by niubbone
Link to comment
Share on other sites

Also, after selecting the question, you remove it from $Domande, however you don't remove the corresponding answers from $Risposte after you are done processing them. After a lower index question is selected, the higher index questions shift one index down, but the answers stay the same. When a higher index question is selected, the answers no longer match the question.

Link to comment
Share on other sites

Thanks to all. Been very Helpful. Modified the code for better working, But still can't get out of this :mellow:

Sometimes it runs sometimes not, and still badly... any ideas why?

Again, try to run it in scite for better and fast understanding.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.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("worktest", 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)
                                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 $DomandeDifferenti[4]
    Local $RisposteMischiate[16]
    Local $i=1
    Local $r=4
    Local $numeridom[5]=[1,2,3,4,5]
    For $z=1 To 4
        Local $GiroDomande=$numeridom[Random(0,UBound($numeridom)-1,1)]
        _ArrayDelete($numeridom,$GiroDomande-1)
        Select
            Case $GiroDomande=1
                $DomandeDifferenti[$z-1]=$DomandaA[0]
                _ArrayDelete($DomandaA,0)
                Local $RisposteInOrdine[4]=[$DomandaA[0],$DomandaA[1],$DomandaA[2],$DomandaA[4]]
            Case $GiroDomande=2
                $DomandeDifferenti[$z-1]=$DomandaB[0]
                _ArrayDelete($DomandaB,0)
                Local $RisposteInOrdine[4]=[$DomandaB[0],$DomandaB[1],$DomandaB[2],$DomandaB[3]]
            Case $GiroDomande=3
                $DomandeDifferenti[$z-1]=$DomandaC[0]
                _ArrayDelete($DomandaC,0)
                Local $RisposteInOrdine[4]=[$DomandaC[0],$DomandaC[1],$DomandaC[2],$DomandaC[3]]
            Case $GiroDomande=4
                $DomandeDifferenti[$z-1]=$DomandaD[0]
                _ArrayDelete($DomandaD,0)
                Local $RisposteInOrdine[4]=[$DomandaD[0],$DomandaD[1],$DomandaD[2],$DomandaD[3]]
            Case $GiroDomande=5
                $DomandeDifferenti[$z-1]=$DomandaE[0]
                _ArrayDelete($DomandaE,0)
                Local $RisposteInOrdine[4]=[$DomandaE[0],$DomandaE[1],$DomandaE[2],$DomandaE[3]]
        EndSelect
        For $k=$i To $r
            Local $CopiaRispOrdine=$RisposteInOrdine
            Local $GiroRispInOrdine=Random(0,Ubound($CopiaRispOrdine)-1,1)
            $RisposteMischiate[$k-1]=$CopiaRispOrdine[$GiroRispInOrdine]
            _ArrayDelete($CopiaRispOrdine,$GiroRispInOrdine)
        Next
        $i+=4
        $r+=4
    Next
    Local $MultiDomERisp[2][16]=[[$DomandeDifferenti[0],$DomandeDifferenti[1],$DomandeDifferenti[2],$DomandeDifferenti[3]], _
    [$RisposteMischiate[0],$RisposteMischiate[1],$RisposteMischiate[2],$RisposteMischiate[3],$RisposteMischiate[4], _
    $RisposteMischiate[5],$RisposteMischiate[6],$RisposteMischiate[7],$RisposteMischiate[8],$RisposteMischiate[9], _
    $RisposteMischiate[10],$RisposteMischiate[11],$RisposteMischiate[12],$RisposteMischiate[13],$RisposteMischiate[14], _
    $RisposteMischiate[15]]]
    Return $MultiDomERisp
EndFunc
Edited by niubbone
Link to comment
Share on other sites

Look at this:

Line 77 - Local $DomandaA[5]=["domA","a1","a2","a3","a4"] ;declare a 5 row array

Line 91 - _ArrayDelete($DomandaA,0) ;remove one row (4 rows remain)

Line 92 - Local $RisposteInOrdine[4]=[$DomandaA[0],$DomandaA[1],$DomandaA[2],$DomandaA[4]] ;read the 5th row.

Link to comment
Share on other sites

Thanks again for the replies. As you can see I'm trying hard and still didn't came up with nothing. It's lot of time I am trying this....

The output in the GUI should be like this:

1)DomA

a1

a3

a2

a4

2)DomE

e2

e1

e4

e3

3)DomB

b3

b1

b4

b2

And so on. Everytime Different but whichever question it's chosen it should respect a link with his replies (DomA with a1-a4 replies, DomB with b1-b4 and so on)

I tried hard for over a month but can't solve this... Anyone of you see where the problem is?

Keep giving this error:

(107) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Local $RisposteInOrdine[4]=[$DomandaE[0],$DomandaE[1],$DomandaE[2],$DomandaE[3]]

Local $RisposteInOrdine[4]=[$DomandaE[0],$DomandaE[1],$DomandaE[2],^ ERROR

but not in the same line, everytime is different (some times $DomandaE[2],^ ERROR, others $DomandaB[2],^ ERROR, depending on the random case...)

Many thanks... and sorry for bothering

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.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("Worktest", 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)
                                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 $DomandeDifferenti[4]
    Local $RisposteMischiate[16]
    Local $i=1
    Local $r=4
    For $z=1 To 4
        Local $numeridom[5]=[1,2,3,4,5]
        Local $GiroDomande=$numeridom[Random(0,UBound($numeridom)-1,1)]
        _ArrayDelete($numeridom,$GiroDomande-1)
        Select
            Case $GiroDomande=1
                $DomandeDifferenti[$z-1]=$DomandaA[0]
                _ArrayDelete($DomandaA,0)
                Local $RisposteInOrdine[4]=[$DomandaA[0],$DomandaA[1],$DomandaA[2],$DomandaA[3]]
            Case $GiroDomande=2
                $DomandeDifferenti[$z-1]=$DomandaB[0]
                _ArrayDelete($DomandaB,0)
                Local $RisposteInOrdine[4]=[$DomandaB[0],$DomandaB[1],$DomandaB[2],$DomandaB[3]]
            Case $GiroDomande=3
                $DomandeDifferenti[$z-1]=$DomandaC[0]
                _ArrayDelete($DomandaC,0)
                Local $RisposteInOrdine[4]=[$DomandaC[0],$DomandaC[1],$DomandaC[2],$DomandaC[3]]
            Case $GiroDomande=4
                $DomandeDifferenti[$z-1]=$DomandaD[0]
                _ArrayDelete($DomandaD,0)
                Local $RisposteInOrdine[4]=[$DomandaD[0],$DomandaD[1],$DomandaD[2],$DomandaD[3]]
            Case $GiroDomande=5
                $DomandeDifferenti[$z-1]=$DomandaE[0]
                _ArrayDelete($DomandaE,0)
                Local $RisposteInOrdine[4]=[$DomandaE[0],$DomandaE[1],$DomandaE[2],$DomandaE[3]]
        EndSelect
        For $k=$i To $r
            Local $numeririsp[4]=[0,1,2,3]
            Local $CopiaRispOrdine=$RisposteInOrdine
            Local $GiroRispInOrdine=$numeririsp[Random(0,Ubound($numeririsp)-1,1)]
            _ArrayDelete($numeririsp,$GiroRispInOrdine)
            $RisposteMischiate[$k-1]=$CopiaRispOrdine[$GiroRispInOrdine]
            _ArrayDelete($CopiaRispOrdine,$GiroRispInOrdine)
        Next
        $i+=4
        $r+=4
    Next
    Local $MultiDomERisp[2][16]=[[$DomandeDifferenti[0],$DomandeDifferenti[1],$DomandeDifferenti[2],$DomandeDifferenti[3]], _
    [$RisposteMischiate[0],$RisposteMischiate[1],$RisposteMischiate[2],$RisposteMischiate[3],$RisposteMischiate[4], _
    $RisposteMischiate[5],$RisposteMischiate[6],$RisposteMischiate[7],$RisposteMischiate[8],$RisposteMischiate[9], _
    $RisposteMischiate[10],$RisposteMischiate[11],$RisposteMischiate[12],$RisposteMischiate[13],$RisposteMischiate[14], _
    $RisposteMischiate[15]]]
    Return $MultiDomERisp
EndFunc

If you need better formatting, or a bit of translation on the above code just ask.

Link to comment
Share on other sites

It is an interesting error.

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"]
; ....
            Case $GiroDomande = 1
                $DomandeDifferenti[$z - 1] = $DomandaA[0]
                _ArrayDisplay($DomandaA)
                _ArrayDelete($DomandaA, 0)
                _ArrayDisplay($DomandaA)
                Local $RisposteInOrdine[4] = [$DomandaA[0], $DomandaA[1], $DomandaA[2], $DomandaA[3]]

Looking at the ArrayDisplay I see no reason for the error to occur as DomandaA does have 4 elements. DomandaA[3] should be valid.

Upon a closer look it is clear that the ArrayDelete function is running more than once on the same array, thus reducing its size every interation.

I changed your select statement slighlty and added #AutoIt3Wrapper_Run_Debug_Mode=Y to the top of the script.

Select
            Case $GiroDomande = 1
                $DomandeDifferenti[$z - 1] = $DomandaA[0]
                _ArrayDelete($DomandaA, 4)
                If UBound($DomandaA) <> 4 Then
                    ConsoleWriteError(" UBound test failed ending now")
                    Exit
                EndIf
                Local $RisposteInOrdine[4] = [$DomandaA[0], $DomandaA[1], $DomandaA[2], $DomandaA[3]]
            Case $GiroDomande = 2
                $DomandeDifferenti[$z - 1] = $DomandaB[0]
                _ArrayDelete($DomandaB, 0)
                If UBound($DomandaA) <> 4 Then
                    ConsoleWriteError(" UBound test failed ending now")
                    Exit
                EndIf
                Local $RisposteInOrdine[4] = [$DomandaB[0], $DomandaB[1], $DomandaB[2], $DomandaB[3]]
            Case $GiroDomande = 3
                $DomandeDifferenti[$z - 1] = $DomandaC[0]
                _ArrayDelete($DomandaC, 0)
                If UBound($DomandaC) <> 4 Then
                    ConsoleWriteError(" UBound test failed ending now")
                    Exit
                EndIf
                Local $RisposteInOrdine[4] = [$DomandaC[0], $DomandaC[1], $DomandaC[2], $DomandaC[3]]
            Case $GiroDomande = 4
                $DomandeDifferenti[$z - 1] = $DomandaD[0]
                _ArrayDelete($DomandaD, 0)
                If UBound($DomandaD) <> 4 Then
                    ConsoleWriteError(" UBound test failed ending now")
                    Exit
                EndIf
                Local $RisposteInOrdine[4] = [$DomandaD[0], $DomandaD[1], $DomandaD[2], $DomandaD[3]]
            Case $GiroDomande = 5
                $DomandeDifferenti[$z - 1] = $DomandaE[0]
                _ArrayDelete($DomandaE, 0)
                If UBound($DomandaE) <> 4 Then
                    ConsoleWriteError(" UBound test failed ending now")
                    Exit
                EndIf
                Local $RisposteInOrdine[4] = [$DomandaE[0], $DomandaE[1], $DomandaE[2], $DomandaE[3]]
        EndSelect

Not sure how you are going to protect against that but I found your error.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

EDIT:

Found solution for the before problem, which is making a case like this:

Case $GiroDomande=1
                $DomandeDifferenti[$z-1]=$DomandaA[0]
                If $DomandaA[0]="DomA" Then
                _ArrayDelete($DomandaA,0)
                EndIf
                Local $RisposteInOrdine[4]=[$DomandaA[0],$DomandaA[1],$DomandaA[2],$DomandaA[3]]

So it won't run more than once. Now the form shows everytime withouth errors.

Though, question are still badly randomized like in the picture below.

-------------------

Thanks very much bo8ster!

At least now I have a clue of what it is... Been for long time correcting and modifying the code ending with same result. So, from what you discovered I guess i have to rewrite this. Though I'm new, I always liked to make the code the most smart I can get, which from my point of view so if is putting up the most useful function/code in the smallest number of lines of code. So I like to spend more time becoming crazy on a function like this (which is now a bit advanced for me) than making a simpler but longer code.

Another note: maybe this depend by the wrong gestion of the code by autoit, or it's just me, don't know, but when the code luckily (yeah, sometimes it's just fine and doesn't finds missing elements arrays) the result is screwed anyways:

Posted Image

As you see correspondances are always violated.

Before getting to the problem I am now, these were my easier solutions:

1)Separating the choiche of questions and answer in 2 different functions, so the first choses a question, the second choses 4 answers related to the Return value of the first, and a third functions runs the whole process of the 2 functions 4 times.

Something like this

Func Compiletest()

for $i=1 to 4

ChooseQuestion()

ChooseAnswer()

Next

Return $Result[4]

EndFunc

Func ChooseQuestion()

Randomly Choose 1 question

Return $question

EndFunc

Func ChooseAnswer()

Randomly mixes 4 answers

based on the output of

ChooseQuestion()

EndFunc

and then compile the test screen.

2) Easiest solution. Divide the test in 4 pages, every page with a question. This would simplify also the multiple radio button problem, since I don't know how to handle all those radio buttons and I didn't find much help in the forum about it. So the test would be 4 pages, you reply one question and click next and so on.

Since this seems a limit of autoit, I can't think of other solutions...

Edited by niubbone
Link to comment
Share on other sites

An interesting issue. Post the entire program and I will give it a run to see what is going on. It is hard understand what you mean without running it.

Can you please also tell me what you want the output to look like. I am going to assume something like. Just wanna be sure on the issue and what you wish the program to do.

DomA

a1

a4

a2

a3

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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...