Heres a multiple choice quiz program I made. You put the answers in a CSV and it asks the questions.
FilePath := "Test.csv"
Title := "Test Quiz"
Questions := Object(), QCount := 0
Loop, Read, % FilePath
{
Line := A_Index
Loop, Parse, A_LoopReadLine, CSV
{
Item := A_Index
If (Item == 1)
Questions[Line,"Q"] := A_LoopField
Else If (Item == 2)
Questions[Line,"a"] := A_LoopField
Else If (Item == 3)
Questions[Line,"b"] := A_LoopField
Else If (Item == 4)
Questions[Line,"c"] := A_LoopField
Else If (Item == 5)
Questions[Line,"d"] := A_LoopField
Else If (Item == 6)
Questions[Line,"S"] := A_LoopField
}
QCount++
}
Gui, Font, s12
Gui, Add, Text, w315 vQText
Gui, Font
Gui, Add, Radio, vA Group w300
Gui, Add, Radio, vB w300
Gui, Add, Radio, vC w300
Gui, Add, Radio, vD w300
Gui, Font, s13
Gui, Add, Button, gNext, Next
QNum := 0 ;The current question that will be shown
QCorrect := 0
GoSub, Next
Gui, Show,, % Title
return
Next:
If (QNum)
GoSub, CheckAnswer
QNum++
If (QNum > QCount)
{
GoSub, Done
return
}
GuiControl, Text, QText, % Questions[QNum,"Q"]
GuiControl, Text, A, % Questions[QNum,"a"]
GuiControl, Text, B, % Questions[QNum,"b"]
GuiControl, Text, C, % Questions[QNum,"c"]
GuiControl, Text, D, % Questions[QNum,"d"]
return
CheckAnswer:
Gui, Submit, NoHide
Correct := Questions[QNum,"S"]
If (%Correct% = True) ;For example, If (c = true)
QCorrect++
GuiControl,, A, 0
GuiControl,, B, 0
GuiControl,, C, 0
GuiControl,, D, 0
return
Done:
Msgbox You got %QCorrect% out of %QCount%!
ExitApp
returnAnd an example CSV file. The format is question, answer1, answer2, answer3, answer4, correct answer (letter). It only currently works with four options.
"What is 1+1?","7","32","2","who cares...","c"
"Spell ""The"".","the","what?","no thanks","no!","a"
"What is the answer to life, the universe and everything?","Pie", "7", "idk","42!","d"