Jump to content

help me to finish Quiz ,please


Recommended Posts

hello everybody

I'm working on a quiz depending on "ini" files:

DB.ini : to get the questions 

ans.ini : to save the answers

the quiz I'm working can save the previous answers but I'm facing a problem when back and forward 

this is the main code

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Date.au3>
#include <StaticConstants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#NoTrayIcon
Opt("TrayIconHide", 1)
Opt("MustDeclareVars", 1)
Opt("GUICloseOnESC", 0) ;1=ESC  closes, 0=ESC won't close
;~ ----------------------------------------------------------------------
Local $qui_width,$qui_hight,$GUIMsg,$var_qs,$Key_qs,$xi,$TXTxLen,$data_ans,$ans_ini
Local $QSTN,$A,$B,$C,$D,$Aopt,$Bopt,$Copt,$Dopt

Local $var_ini,$Key_ans,$sData0


Local $File = "DB.ini", $font = "Lucida Console"
Global $i = 1



$ans_ini = "ans.ini"
$sData0 = "ans=1"

If FileExists($ans_ini) = 0 Then
    FileOpen($ans_ini, 1)
    FileClose($ans_ini)
    IniWriteSection($ans_ini, "1", $sData0)
 EndIf




$qui_width = 1250
$qui_hight = 675
local $hGUI = GUICreate("Quiz" , $qui_width, $qui_hight)
GUISetBkColor(0xFFFFD4)
;~ ---------------------------------------------------------
guictrlcreategroup("question", 20, 35, $qui_width-40, 75 )
;~ ---------------------------------------------------------




guictrlcreategroup("answers", 20, 125, 500, 424 )
;~ ---------------------------------------------------------
guictrlcreategroup("A", 40, 145, 460, 90 )
GUICtrlSetFont(-1, 10, 650, $font)
guictrlcreategroup("B", 40, 243, 460, 90 )
GUICtrlSetFont(-1, 10, 650, $font)
guictrlcreategroup("C", 40, 341, 460, 90 )
GUICtrlSetFont(-1, 10, 650, $font)
guictrlcreategroup("D", 40, 439, 460, 90 )
GUICtrlSetFont(-1, 10, 650, $font)
;~ ---------------------------------------------------------
;~ A


$A = GUICtrlCreateLabel("",75 ,185,420,45,$GUI_ONTOP) ; Question text
GUICtrlSetFont(-1, 12,650, $font)
GUICtrlSetColor(-1, 0x008fd7)
;~ ---------------------------------
$Aopt = GUICtrlCreateRadio("", 57,170,15,50)
GUICtrlSetFont(-1, 12,650, $font)
;~ ---------------------------------------------------------
;~ B
$B = GUICtrlCreateLabel("",75 ,283,420,45) ; Question text
GUICtrlSetFont(-1, 12,650, $font)
GUICtrlSetColor(-1, 0x008fd7)
;~ ---------------------------------
$Bopt = GUICtrlCreateRadio("", 57,268,15,50)
GUICtrlSetFont(-1, 12,650, $font)
;~ ---------------------------------------------------------
;~ C
$C = GUICtrlCreateLabel("",75 ,381,420,45) ; Question text
GUICtrlSetFont(-1, 12,650, $font)
GUICtrlSetColor(-1, 0x008fd7)
;~ ---------------------------------
$Copt = GUICtrlCreateRadio("", 57,366,15,50)
GUICtrlSetFont(-1, 12,650, $font)
;~ ---------------------------------------------------------
;~ D
$D = GUICtrlCreateLabel("",75 ,479,420,45) ; Question text
GUICtrlSetFont(-1, 12,650, $font)
GUICtrlSetColor(-1, 0x008fd7)
;~ ---------------------------------
$Dopt = GUICtrlCreateRadio("", 57,464,15,50)
GUICtrlSetFont(-1, 12,650, $font)
;~ ---------------------------------------------------------
Local $count = GUICtrlCreateLabel("",500 ,575,420,45) ; Question text
GUICtrlSetFont(-1, 12,650, $font)
GUICtrlSetColor(-1, 0x008fd7)


;~ Buttons
Local $next = GUICtrlCreateButton("next",300,600,100,50)
Local $prev = GUICtrlCreateButton("prev",100,600,100,50)



;~ ---------------------------------------------------------
guictrlcreategroup("img", 540, 125, 690, 424 )
;~ ---------------------------------------------------------

NextData()
GUISetState(@SW_SHOW)

GUICtrlSetState($prev,$GUI_DISABLE)


While 1
   $GUIMsg = GUIGetMsg()
   Select
   Case $GUIMsg = $GUI_EVENT_CLOSE;, $nExititem
      FileDelete($ans_ini)
      Exit
;~    --------------------------------------------$unchk
   Case $GUIMsg = $next
      DetectChkOpt()
;~    --------------------------------------------
   Case $GUIMsg = $prev
      prevData()
   EndSelect

WEnd




Func NextData()
   $var_ini = IniReadSectionNames($ans_ini)
   $var_qs = IniReadSectionNames($File)

   ;MsgBox(0,"", "$i=" & $i & " - lav[0]=" & $var_ini[0])

   If $i <= $var_qs[0] Then
      If $i > $var_ini[0] Then
         GUICtrlSetState($Bopt,$GUI_UNCHECKED)
         GUICtrlSetState($Aopt,$GUI_UNCHECKED)
         GUICtrlSetState($Copt,$GUI_UNCHECKED)
         GUICtrlSetState($Dopt,$GUI_UNCHECKED)

         $Key_qs = IniReadSection($File, $var_qs[$i])
         ;~ ---------------------------------------------------------
         $QSTN = GUICtrlCreateLabel($Key_qs[1][1] ,75,64,500,45) ; Question text
         GUICtrlSetFont(-1, 12,650, $font)
         GUICtrlSetColor(-1, 0x008fd7)
         ;~    ----------------------------------------------------------
         GUICtrlSetData($A,$Key_qs[2][1])
         GUICtrlSetData($B,$Key_qs[3][1])
         GUICtrlSetData($C,$Key_qs[4][1])

         If $Key_qs[5][1] = "-" Then
           GUICtrlSetState($Dopt,$GUI_HIDE)
           GUICtrlSetData($D,"")
         Else
            GUICtrlSetState($Dopt,$GUI_SHOW)
            GUICtrlSetData($D,$Key_qs[5][1])
         EndIf

            $i=$i+1
      Else

         $Key_ans = IniReadSection($ans_ini, $var_ini[$i])
         If $Key_ans[1][1] = "A" Then
            GUICtrlSetState($Aopt,$GUI_CHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "B" Then
            GUICtrlSetState($Bopt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "C" Then
            GUICtrlSetState($Copt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "D" Then
            GUICtrlSetState($Dopt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
         EndIf

         $Key_qs = IniReadSection($File, $var_qs[$i])
         ;~ ---------------------------------------------------------
         $QSTN = GUICtrlCreateLabel($Key_qs[1][1] ,75 ,64,500,45) ; Question text
         GUICtrlSetFont(-1, 12,650, $font)
         GUICtrlSetColor(-1, 0x008fd7)
         ;~    ----------------------------------------------------------
         GUICtrlSetData($A,$Key_qs[2][1])
         GUICtrlSetData($B,$Key_qs[3][1])
         GUICtrlSetData($C,$Key_qs[4][1])

         If $Key_qs[5][1] = "-" Then
           GUICtrlSetState($Dopt,$GUI_HIDE)
           GUICtrlSetData($D,"")
         Else
            GUICtrlSetState($Dopt,$GUI_SHOW)
            GUICtrlSetData($D,$Key_qs[5][1])
         EndIf

            $i=$i+1

     EndIf

   Else

      Result()

   EndIf

GUICtrlSetData($count,$i)

EndFunc



Func prevData()


   $var_ini = IniReadSectionNames($ans_ini)
   $var_qs = IniReadSectionNames($File)

   If $var_ini[0] = 1 Then
      $i=$var_ini[0]
   Else
      $i=$var_ini[0]-1
   EndIf

   MsgBox(0,"",$var_ini[0])

   $Key_ans = IniReadSection($ans_ini, $var_ini[$i])
   If $var_qs[$i] = $var_qs[1] Then
      GUICtrlSetState($prev,$GUI_DISABLE)
             If $Key_ans[1][1] = "A" Then
            GUICtrlSetState($Aopt,$GUI_CHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "B" Then
            GUICtrlSetState($Bopt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "C" Then
            GUICtrlSetState($Copt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "D" Then
            GUICtrlSetState($Dopt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
         EndIf

         $Key_qs = IniReadSection($File, $var_qs[$i])

         $QSTN = GUICtrlCreateLabel($Key_qs[1][1] ,75 ,64,500,45) ; Question text
         GUICtrlSetFont(-1, 12,650, $font)
         GUICtrlSetColor(-1, 0x008fd7)
         ;~    ----------------------------------------------------------
         GUICtrlSetData($A,$Key_qs[2][1])
         GUICtrlSetData($B,$Key_qs[3][1])
         GUICtrlSetData($C,$Key_qs[4][1])

         If $Key_qs[5][1] = "-" Then
           GUICtrlSetState($Dopt,$GUI_HIDE)
           GUICtrlSetData($D,"")
         Else
            GUICtrlSetState($Dopt,$GUI_SHOW)
            GUICtrlSetData($D,$Key_qs[5][1])
         EndIf

   Else

         If $Key_ans[1][1] = "A" Then
            GUICtrlSetState($Aopt,$GUI_CHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "B" Then
            GUICtrlSetState($Bopt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "C" Then
            GUICtrlSetState($Copt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "D" Then
            GUICtrlSetState($Dopt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
         EndIf

         $Key_qs = IniReadSection($File, $var_qs[$i])

         $QSTN = GUICtrlCreateLabel($Key_qs[1][1] ,75 ,64,500,45) ; Question text
         GUICtrlSetFont(-1, 12,650, $font)
         GUICtrlSetColor(-1, 0x008fd7)
         ;~    ----------------------------------------------------------
         GUICtrlSetData($A,$Key_qs[2][1])
         GUICtrlSetData($B,$Key_qs[3][1])
         GUICtrlSetData($C,$Key_qs[4][1])

         If $Key_qs[5][1] = "-" Then
           GUICtrlSetState($Dopt,$GUI_HIDE)
           GUICtrlSetData($D,"")
         Else
            GUICtrlSetState($Dopt,$GUI_SHOW)
            GUICtrlSetData($D,$Key_qs[5][1])
         EndIf

   EndIf


EndFunc



Func DetectChkOpt()
   Select
   Case GUICtrlRead($Aopt) = 1
      $data_ans = "ans[" & $i-1 & "]=A"
      IniWriteSection($ans_ini, $i-1, $data_ans)
      MsgBox(0,""," $i=" & $i)
      GUICtrlSetData($QSTN,"")
      GUICtrlSetState($prev,$GUI_ENABLE)
      NextData()
;~    =======================
   Case GUICtrlRead($Bopt) = 1
      $data_ans = "ans[" & $i-1 & "]=B"
      IniWriteSection($ans_ini, $i-1, $data_ans)
      MsgBox(0,""," $i=" & $i)
      GUICtrlSetData($QSTN,"")
      GUICtrlSetState($prev,$GUI_ENABLE)
      NextData()
;~    =======================
   Case GUICtrlRead($Copt) = 1
      $data_ans = "ans[" & $i-1 & "]=C"
      IniWriteSection($ans_ini, $i-1, $data_ans)
      MsgBox(0,""," $i=" & $i)
      GUICtrlSetData($QSTN,"")
      GUICtrlSetState($prev,$GUI_ENABLE)
      NextData()
;~    =======================
   Case GUICtrlRead($Dopt) = 1
      $data_ans = "ans[" & $i-1 & "]=D"
      IniWriteSection($ans_ini, $i-1, $data_ans)
      MsgBox(0,""," $i=" & $i)
      GUICtrlSetData($QSTN,"")
      GUICtrlSetState($prev,$GUI_ENABLE)
      NextData()
;~    =======================
   Case Else
      MsgBox(0,"attention","please choose one of these options")
   EndSelect
EndFunc



Func Result()
   Local $rslt = 0
   $var_qs = IniReadSectionNames($File)
   $var_ini = IniReadSectionNames($ans_ini)
;~ ---------------------------------------------------
   For $l = 1 To $var_ini[0]
      $Key_qs = IniReadSection($File, $var_qs[$l])
      $Key_ans = IniReadSection($ans_ini, $var_ini[$l])
      If $Key_ans[1][1] = $Key_qs[6][1] Then
         $rslt = $rslt + 1
      EndIf
   Next
;~ ---------------------------------------------------
   GUICtrlSetData($QSTN,$Key_qs[1][1])
   ;MsgBox(0,"",Ubound($ansr) & "   " & $ai)
   MsgBox(0,"Result", $rslt & " of " & $var_qs[0] )
   $i = $var_ini[0]
   MsgBox(0,"$i = $var_ini[0]-1", $i )
EndFunc

 

and this is example of the questions file: DB.ini

[1]
QS = What is the biggest planet in our solar system?
ans1 = Earth
ans2 = Jupiter
ans3 = Pluto
ans4 = - 
true = B
img = 
[2]
QS = What is the name of the element with the chemical symbol ‘He’?
ans1 = Helium
ans2 = Hydrogen 
ans3 = Oxygen
ans4 = nitrogen
true = A
img = 
[3]
QS = How many bones do sharks have in their bodies?
ans1 = 20
ans2 = 50
ans3 = 0
ans4 = 10
true = C
img =

 

may be the code is long or has many errors but that what I can :)

 

please help me I have to finish soon please 

 

Edited by Soledad
Link to comment
Share on other sites

I've mode a new code and correct some issues 

everything become OK except one thing 

 

when reach to the end and get the result, I backward to the first and it's OK but when forward to the last question it changes the answer although I import the answers from ini file

 

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Date.au3>
#include <StaticConstants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#NoTrayIcon
Opt("TrayIconHide", 1)
Opt("MustDeclareVars", 1)
Opt("GUICloseOnESC", 0) ;1=ESC  closes, 0=ESC won't close
;~ ----------------------------------------------------------------------
Local $qui_width,$qui_hight,$GUIMsg,$var_qs,$Key_qs,$xi,$TXTxLen,$data_ans,$ans_ini
Local $QSTN,$A,$B,$C,$D,$Aopt,$Bopt,$Copt,$Dopt

Local $RQSTN,$sCase,$aResults,$Rsize,$ip,$in

Local $var_ans,$Key_ans,$sData0


Local $File = "DB.ini", $font = "Lucida Console"
Local $in = 1



$ans_ini = "ans.ini"
$sData0 = "ans=1"

If FileExists($ans_ini) = 0 Then
    FileOpen($ans_ini, 1)
    FileClose($ans_ini)
    IniWriteSection($ans_ini, "1", $sData0)
 EndIf




$qui_width = 1250
$qui_hight = 675
local $hGUI = GUICreate("Quiz" , $qui_width, $qui_hight)
GUISetBkColor(0xFFFFD4)
;~ ---------------------------------------------------------
guictrlcreategroup("question", 20, 35, $qui_width-40, 75 )
;~ ---------------------------------------------------------




guictrlcreategroup("answers", 20, 125, 500, 424 )
;~ ---------------------------------------------------------
guictrlcreategroup("A", 40, 145, 460, 90 )
GUICtrlSetFont(-1, 10, 650, $font)
guictrlcreategroup("B", 40, 243, 460, 90 )
GUICtrlSetFont(-1, 10, 650, $font)
guictrlcreategroup("C", 40, 341, 460, 90 )
GUICtrlSetFont(-1, 10, 650, $font)
guictrlcreategroup("D", 40, 439, 460, 90 )
GUICtrlSetFont(-1, 10, 650, $font)
;~ ---------------------------------------------------------
;~ A


$A = GUICtrlCreateLabel("",75 ,185,420,45,$GUI_ONTOP) ; Question text
GUICtrlSetFont(-1, 12,650, $font)
GUICtrlSetColor(-1, 0x008fd7)
;~ ---------------------------------
$Aopt = GUICtrlCreateRadio("", 57,170,15,50)
GUICtrlSetFont(-1, 12,650, $font)
;~ ---------------------------------------------------------
;~ B
$B = GUICtrlCreateLabel("",75 ,283,420,45) ; Question text
GUICtrlSetFont(-1, 12,650, $font)
GUICtrlSetColor(-1, 0x008fd7)
;~ ---------------------------------
$Bopt = GUICtrlCreateRadio("", 57,268,15,50)
GUICtrlSetFont(-1, 12,650, $font)
;~ ---------------------------------------------------------
;~ C
$C = GUICtrlCreateLabel("",75 ,381,420,45) ; Question text
GUICtrlSetFont(-1, 12,650, $font)
GUICtrlSetColor(-1, 0x008fd7)
;~ ---------------------------------
$Copt = GUICtrlCreateRadio("", 57,366,15,50)
GUICtrlSetFont(-1, 12,650, $font)
;~ ---------------------------------------------------------
;~ D
$D = GUICtrlCreateLabel("",75 ,479,420,45) ; Question text
GUICtrlSetFont(-1, 12,650, $font)
GUICtrlSetColor(-1, 0x008fd7)
;~ ---------------------------------
$Dopt = GUICtrlCreateRadio("", 57,464,15,50)
GUICtrlSetFont(-1, 12,650, $font)
;~ ---------------------------------------------------------
Local $count = GUICtrlCreateLabel("",500 ,575,420,45) ; Question text
GUICtrlSetFont(-1, 12,650, $font)
GUICtrlSetColor(-1, 0x008fd7)


;~ Buttons
Local $next = GUICtrlCreateButton("next",300,600,100,50)
Local $prev = GUICtrlCreateButton("prev",100,600,100,50)



;~ ---------------------------------------------------------
guictrlcreategroup("img", 540, 125, 690, 424 )
;~ ---------------------------------------------------------

FstData()
GUISetState(@SW_SHOW)

GUICtrlSetState($prev,$GUI_DISABLE)


While 1
   $GUIMsg = GUIGetMsg()
   Select
   Case $GUIMsg = $GUI_EVENT_CLOSE;, $nExititem
      FileDelete($ans_ini)
      Exit
;~    --------------------------------------------$unchk
   Case $GUIMsg = $next
      DetectChkOpt()
;~    --------------------------------------------
   Case $GUIMsg = $prev
      PRData()
   EndSelect

WEnd

Func NXData()
   $var_ans = IniReadSectionNames($ans_ini)
   $var_qs = IniReadSectionNames($File)

   $RQSTN = GUICtrlRead($QSTN,1)
   $sCase = ""
   $aResults = StringRegExp(FileRead($File), $sCase & "(?m:^).*" & $RQSTN & ".*(?:\v|$)+", 3)
   $Rsize = UBound($aResults)
   $in = StringTrimLeft(StringSplit($aResults[0],"=]")[1],3)

;MsgBox(0,"$in="& $in ,StringSplit($aResults[0],"=")[2])


   If $in <= $var_qs[0] then

      If $in < $var_qs[0] Then
         $in=$in+1
      Else
         $in=$in
      EndIf

;~    write options
      $Key_qs = IniReadSection($File, $var_qs[$in])
      $QSTN = GUICtrlCreateLabel($Key_qs[1][1] ,75 ,64,500,45) ; Question text
      GUICtrlSetFont(-1, 12,650, $font)
      GUICtrlSetColor(-1, 0x008fd7)
      ;~    ----------------------------------------------------------
      GUICtrlSetData($A,$Key_qs[2][1])
      GUICtrlSetData($B,$Key_qs[3][1])
      GUICtrlSetData($C,$Key_qs[4][1])

      If $Key_qs[5][1] = "-" Then
        GUICtrlSetState($Dopt,$GUI_HIDE)
        GUICtrlSetData($D,"")
      Else
         GUICtrlSetState($Dopt,$GUI_SHOW)
         GUICtrlSetData($D,$Key_qs[5][1])
      EndIf

;MsgBox(0,"$var_ans[0]",$var_ans[0])
;~    check answers
      If $in > $var_ans[0] Then
         GUICtrlSetState($Bopt,$GUI_UNCHECKED)
         GUICtrlSetState($Aopt,$GUI_UNCHECKED)
         GUICtrlSetState($Copt,$GUI_UNCHECKED)
         GUICtrlSetState($Dopt,$GUI_UNCHECKED)
      ElseIf $in < $var_ans[0] Then

;~       check for the last item to enter result
         $RQSTN = GUICtrlRead($QSTN,1)
         $sCase = ""
         $aResults = StringRegExp(FileRead($File), $sCase & "(?m:^).*" & $RQSTN & ".*(?:\v|$)+", 3)
         $Rsize = UBound($aResults)
         $in = StringTrimLeft(StringSplit($aResults[0],"=]")[1],3)
         $Key_ans = IniReadSection($ans_ini, $var_ans[$in])
         If $Key_ans[1][1] = "A" Then
            GUICtrlSetState($Aopt,$GUI_CHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "B" Then
            GUICtrlSetState($Bopt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "C" Then
            GUICtrlSetState($Copt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "D" Then
            GUICtrlSetState($Dopt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
         EndIf

      Else
;~       check for the last item to enter result
         $RQSTN = GUICtrlRead($QSTN,1)
         $sCase = ""
         $aResults = StringRegExp(FileRead($File), $sCase & "(?m:^).*" & $RQSTN & ".*(?:\v|$)+", 3)
         $Rsize = UBound($aResults)
         $in = StringTrimLeft(StringSplit($aResults[0],"=]")[1],3)
         $Key_ans = IniReadSection($ans_ini, $var_ans[$in])
         MsgBox(0,"last page", "$in=" & $in ) ;& "   Key_ans[1][1]=" & Key_ans[1][1]

         If $Key_ans[1][1] = "A" Then
            GUICtrlSetState($Aopt,$GUI_CHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "B" Then
            GUICtrlSetState($Bopt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "C" Then
            GUICtrlSetState($Copt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Dopt,$GUI_UNCHECKED)
         ElseIf $Key_ans[1][1] = "D" Then
            GUICtrlSetState($Dopt,$GUI_CHECKED)
            GUICtrlSetState($Aopt,$GUI_UNCHECKED)
            GUICtrlSetState($Bopt,$GUI_UNCHECKED)
            GUICtrlSetState($Copt,$GUI_UNCHECKED)
         EndIf
         Result()
      EndIf
   EndIf
EndFunc



Func FstData()

   $var_qs = IniReadSectionNames($File)

   GUICtrlSetState($Bopt,$GUI_UNCHECKED)
   GUICtrlSetState($Aopt,$GUI_UNCHECKED)
   GUICtrlSetState($Copt,$GUI_UNCHECKED)
   GUICtrlSetState($Dopt,$GUI_UNCHECKED)

   $Key_qs = IniReadSection($File, $var_qs[1])
   ;~ ---------------------------------------------------------
   $QSTN = GUICtrlCreateLabel($Key_qs[1][1] ,75,64,500,45) ; Question text
   GUICtrlSetFont(-1, 12,650, $font)
   GUICtrlSetColor(-1, 0x008fd7)
   ;~    ----------------------------------------------------------
   GUICtrlSetData($A,$Key_qs[2][1])
   GUICtrlSetData($B,$Key_qs[3][1])


   If $Key_qs[4][1] = "-" Then
     GUICtrlSetState($Copt,$GUI_HIDE)
     GUICtrlSetData($C,"")
   Else
      GUICtrlSetState($Copt,$GUI_SHOW)
      GUICtrlSetData($C,$Key_qs[4][1])
   EndIf


EndFunc

Func PRData()

   $var_ans = IniReadSectionNames($ans_ini)
   $var_qs = IniReadSectionNames($File)

   $RQSTN = GUICtrlRead($QSTN,1)
   $sCase = ""
   $aResults = StringRegExp(FileRead($File), $sCase & "(?m:^).*" & $RQSTN & ".*(?:\v|$)+", 3)
   $Rsize = UBound($aResults)
   $ip = StringTrimLeft(StringSplit($aResults[0],"=]")[1],3)

   If $ip = 2 Then
      GUICtrlSetState($prev,$GUI_DISABLE)
      $Key_ans = IniReadSection($ans_ini, $var_ans[$ip-1])

      If $Key_ans[1][1] = "A" Then
         GUICtrlSetState($Aopt,$GUI_CHECKED)
         GUICtrlSetState($Bopt,$GUI_UNCHECKED)
         GUICtrlSetState($Copt,$GUI_UNCHECKED)
         GUICtrlSetState($Dopt,$GUI_UNCHECKED)
      ElseIf $Key_ans[1][1] = "B" Then
         GUICtrlSetState($Bopt,$GUI_CHECKED)
         GUICtrlSetState($Aopt,$GUI_UNCHECKED)
         GUICtrlSetState($Copt,$GUI_UNCHECKED)
         GUICtrlSetState($Dopt,$GUI_UNCHECKED)
      ElseIf $Key_ans[1][1] = "C" Then
         GUICtrlSetState($Copt,$GUI_CHECKED)
         GUICtrlSetState($Aopt,$GUI_UNCHECKED)
         GUICtrlSetState($Bopt,$GUI_UNCHECKED)
         GUICtrlSetState($Dopt,$GUI_UNCHECKED)
      ElseIf $Key_ans[1][1] = "D" Then
         GUICtrlSetState($Dopt,$GUI_CHECKED)
         GUICtrlSetState($Aopt,$GUI_UNCHECKED)
         GUICtrlSetState($Bopt,$GUI_UNCHECKED)
         GUICtrlSetState($Copt,$GUI_UNCHECKED)
      EndIf

      $Key_qs = IniReadSection($File, $var_qs[$ip-1])
      $QSTN = GUICtrlCreateLabel($Key_qs[1][1] ,75 ,64,500,45) ; Question text
      GUICtrlSetFont(-1, 12,650, $font)
      GUICtrlSetColor(-1, 0x008fd7)
      ;~    ----------------------------------------------------------
      GUICtrlSetData($A,$Key_qs[2][1])
      GUICtrlSetData($B,$Key_qs[3][1])
      GUICtrlSetData($C,$Key_qs[4][1])

      If $Key_qs[5][1] = "-" Then
        GUICtrlSetState($Dopt,$GUI_HIDE)
        GUICtrlSetData($D,"")
      Else
         GUICtrlSetState($Dopt,$GUI_SHOW)
         GUICtrlSetData($D,$Key_qs[5][1])
      EndIf

   Else
      $Key_ans = IniReadSection($ans_ini, $var_ans[$ip-1])

      If $Key_ans[1][1] = "A" Then
         GUICtrlSetState($Aopt,$GUI_CHECKED)
         GUICtrlSetState($Bopt,$GUI_UNCHECKED)
         GUICtrlSetState($Copt,$GUI_UNCHECKED)
         GUICtrlSetState($Dopt,$GUI_UNCHECKED)
      ElseIf $Key_ans[1][1] = "B" Then
         GUICtrlSetState($Bopt,$GUI_CHECKED)
         GUICtrlSetState($Aopt,$GUI_UNCHECKED)
         GUICtrlSetState($Copt,$GUI_UNCHECKED)
         GUICtrlSetState($Dopt,$GUI_UNCHECKED)
      ElseIf $Key_ans[1][1] = "C" Then
         GUICtrlSetState($Copt,$GUI_CHECKED)
         GUICtrlSetState($Aopt,$GUI_UNCHECKED)
         GUICtrlSetState($Bopt,$GUI_UNCHECKED)
         GUICtrlSetState($Dopt,$GUI_UNCHECKED)
      ElseIf $Key_ans[1][1] = "D" Then
         GUICtrlSetState($Dopt,$GUI_CHECKED)
         GUICtrlSetState($Aopt,$GUI_UNCHECKED)
         GUICtrlSetState($Bopt,$GUI_UNCHECKED)
         GUICtrlSetState($Copt,$GUI_UNCHECKED)
      EndIf

      $Key_qs = IniReadSection($File, $var_qs[$ip-1])
      $QSTN = GUICtrlCreateLabel($Key_qs[1][1] ,75 ,64,500,45) ; Question text
      GUICtrlSetFont(-1, 12,650, $font)
      GUICtrlSetColor(-1, 0x008fd7)
      ;~    ----------------------------------------------------------
      GUICtrlSetData($A,$Key_qs[2][1])
      GUICtrlSetData($B,$Key_qs[3][1])
      GUICtrlSetData($C,$Key_qs[4][1])

      If $Key_qs[5][1] = "-" Then
        GUICtrlSetState($Dopt,$GUI_HIDE)
        GUICtrlSetData($D,"")
      Else
         GUICtrlSetState($Dopt,$GUI_SHOW)
         GUICtrlSetData($D,$Key_qs[5][1])
      EndIf

   EndIf




EndFunc


Func DetectChkOpt()
   Select
   Case GUICtrlRead($Aopt) = 1
      $data_ans = "ans[" & $in & "]=A"
      IniWriteSection($ans_ini, $in, $data_ans)
      ;MsgBox(0,""," $i=" & $i)
      ;GUICtrlSetData($QSTN,"")
      GUICtrlSetState($prev,$GUI_ENABLE)
      NXData()
;~    =======================
   Case GUICtrlRead($Bopt) = 1
      $data_ans = "ans[" & $in & "]=B"
      IniWriteSection($ans_ini, $in, $data_ans)
      ;MsgBox(0,""," $i=" & $i)
      ;GUICtrlSetData($QSTN,"")
      GUICtrlSetState($prev,$GUI_ENABLE)
      NXData()
;~    =======================
   Case GUICtrlRead($Copt) = 1
      $data_ans = "ans[" & $in & "]=C"
      IniWriteSection($ans_ini, $in, $data_ans)
      ;MsgBox(0,""," $i=" & $i)
      ;GUICtrlSetData($QSTN,"")
      GUICtrlSetState($prev,$GUI_ENABLE)
      NXData()
;~    =======================
   Case GUICtrlRead($Dopt) = 1
      $data_ans = "ans[" & $in & "]=D"
      IniWriteSection($ans_ini, $in, $data_ans)
      ;MsgBox(0,""," $i=" & $i)
      ;GUICtrlSetData($QSTN,"")
      GUICtrlSetState($prev,$GUI_ENABLE)
      NXData()
;~    =======================
   Case Else
      MsgBox(0,"attention","please choose one of these options")
   EndSelect
EndFunc



Func Result()
   Local $rslt = 0
   $var_qs = IniReadSectionNames($File)
   $var_ans = IniReadSectionNames($ans_ini)
;~ ---------------------------------------------------
   For $l = 1 To $var_ans[0]
      $Key_qs = IniReadSection($File, $var_qs[$l])
      $Key_ans = IniReadSection($ans_ini, $var_ans[$l])
      If $Key_ans[1][1] = $Key_qs[6][1] Then
         $rslt = $rslt + 1
      EndIf
   Next
;~ ---------------------------------------------------
   GUICtrlSetData($QSTN,$Key_qs[1][1])
   ;MsgBox(0,"",Ubound($ansr) & "   " & $ai)
   MsgBox(0,"Result", $rslt & " of " & $var_qs[0] )

EndFunc

Edited by Soledad
Link to comment
Share on other sites

the new mod is getting the number $in by checking the question txt and search in ini file and stringsplite the number 

 

according to this I mod the questions ini file is DB.ini

 

[1]
QS[1]=What is the biggest planet in our solar system?
ans1[1]=Earth
ans2[1]=Jupiter
ans3[1]=Pluto
ans4[1]=-
true = B
img = 
[2]
QS[2]=What is the name of the element with the chemical symbol ‘He’?
ans1[2]=Helium
ans2[2]=Hydrogen
ans3[2]=Oxygen
ans4[2]=nitrogen
true = A
img = 
[3]
QS[3]=How many bones do sharks have in their bodies?
ans1[3]=20
ans2[3]=50
ans3[3]=0
ans4[3]=10
true = C
img =

 

Edited by Soledad
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

×
×
  • Create New...