WilliamasKumeliukas Posted August 6, 2018 Posted August 6, 2018 (edited) Hi, I have an problem I can't figure out what I did wrong in my code: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ColorConstantS.au3> #include <Array.au3> #include <StringConstants.au3> #include <File.au3> #include <WindowsConstants.au3> destroy() Global $file = @TempDir & "\test.txt" FileInstall(@ScriptDir & "\test.txt", $file) Local $msg, $score = 0, $rate, $com Local $qf = StringSplit(StringStripWS(FileRead($file),2),@CRLF ,1) Local $q = "test" & @CRLF & "..." Local $gui = GUICreate("test", 1124,548,-1,-1) $options = GUICtrlCreateMenu("Options") $restart = GUICtrlCreateMenuItem("Open", $options) $about = GUICtrlCreateMenuItem("About", $options) $exit = GUICtrlCreateMenuItem("Exit", $options) $extra = GUICtrlCreateMenu("Extras") $creator = GUICtrlCreateMenu("Custom", $extra) $new = GUICtrlCreateMenuItem("new", $creator) $load = GUICtrlCreateMenuItem("load", $creator) $guide = GUICtrlCreateMenuItem("Quick Guide", $extra) $timer = GUICtrlCreateLabel("test", 952, 472, 44, 30, BitOR($SS_CENTER,$WS_BORDER)) GUICtrlSetFont(-1, 16, 400, 0, "MS Reference Sans Serif") GUICtrlSetResizing(-1, $GUI_DOCKAUTO) Local $info = GUICtrlCreateLabel($q, 220,20,700,200,$SS_CENTER) $fi = GUICtrlSetFont($info, 20) Local $a = GUICtrlCreateRadio("A) ", 300,210,200,50) $fa = GUICtrlSetFont($a, 15) Local $b = GUICtrlCreateRadio("B) ", 300,320,200,50) $fb = GUICtrlSetFont($b, 15) Local $c = GUICtrlCreateRadio("C) ", 800,210,200,50) $fc = GUICtrlSetFont($c, 15) Local $d = GUICtrlCreateRadio("D) ", 800, 320,200,50) $fd = GUICtrlSetFont($d, 15) Local $sign = GUICtrlCreateLabel("", 420, 480) Local $start = GUICtrlCreateButton("start", 20, 20, 100, 50) GUICtrlSetFont($start, 12) Local $valid = GUICtrlCreateButton("Confirm", 20, 20, 100, 50) GUICtrlSetFont($valid, 12) GUICtrlSetState($valid, 32) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE FileClose($file) ExitLoop Case $start qloop() Case $exit ExitLoop Exit EndSwitch WEnd Func timer() ;to Do EndFunc Func qloop() GUICtrlSetState($start, 32) GUICtrlsetState($valid, 16) For $i = 1 To $qf[0] Step 7 GUICtrlSetData($info, $qf[$i]) GUICtrlSetData($a, $qf[$i + 1]) GUICtrlSetData($b, $qf[$i + 2]) GUICtrlSetData($c, $qf[$i + 3]) GUICtrlSetData($d, $qf[$i + 4]) Do $msg = GUIGetMsg() If $msg = $valid Then If StringLeft($qf[$i+5], 99) = GUICtrlread($a, 1) Then $score += 1 MsgBox(0, "", "True" & @CRLF & @CRLF & $qf[$i+5], $GUI) ElseIf StringLeft($qf[$i+5], 99) = GUICtrlRead($b, 1) Then MsgBox(0, "", "True" & @CRLF & @CRLF & $qf[$i+5], $GUI) $score += 1 ElseIf StringLeft($qf[$i+5], 99) = GUICtrlRead($c, 1) Then MsgBox(0, "", "True" & @CRLF & @CRLF & $qf[$i+5], $GUI) $score += 1 ElseIf StringLeft($qf[$i+5], 99) = GUICtrlRead($d, 1) Then MsgBox(0, "", "True" & @CRLF & @CRLF & $qf[$i+5], $GUI) $score += 1 Else MsgBox(0, "", "False" & @CRLF & @CRLF & "The true answer was: " & "[ " & $qf[$i + 5] & " ]" & @CRLF & @CRLF & "why : " & $qf[$i + 6]) EndIf ExitLoop EndIf If $msg = -3 Then Exit Until 0 Next $rate = 100 * $score / ($qf[0] / 2) Switch $rate Case 0 To 24 $com = "no comment" Case 26 To 50 $com = "could be better" Case 51 To 75 $com = "can do better " Case 76 To 99 $com = "Good job !" Case 100 $com = "You won!" EndSwitch GUICtrlSetData($info, " result obtained: " & $rate & "% " & @CRLF & @CRLF & $com) GUICtrlSetState($valid, 32) GUICtrlSetState($start, 16) Return EndFunc Func _hide() ;to Do EndFunc Func destroy() If FileExists(@tempdir & "\test.txt") then FileDelete(@Tempdir & "\test.txt") EndIf EndFunc even though GUICtrlRead return the correct "value/string" and $qf[$i+5] it still managing to consider Stringleft($qf[$i+5]=GUICtrlRead($a, 1) sometimes true sometimes false... here is the "test.txt" Spoiler 1) test A. test #1 B. test #2 C. test #3 D. test #4 C. test #3 info 1 2) 123 A. 451 B. 456 C. 654 D. 321 B. 456 info 2 Regards, ~Williamas Kumeliukas Edited August 6, 2018 by WilliamasKumeliukas Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this: Spoiler #1. I am a native French speaker and learned English mainly from chatting with others players in online games. #2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor. ~WilliamasKumeliukas
mikell Posted August 6, 2018 Posted August 6, 2018 Well, the way you use to check the radio buttons causes the script to always answer "true" You don't check if the concerned radio button is checked or not ... Example If (StringLeft($qf[$i+5], 99) = GUICtrlread($a, 1)) AND GUICtrlread($a) = 1 Then
WilliamasKumeliukas Posted August 7, 2018 Author Posted August 7, 2018 19 hours ago, mikell said: Well, the way you use to check the radio buttons causes the script to always answer "true" You don't check if the concerned radio button is checked or not ... Example If (StringLeft($qf[$i+5], 99) = GUICtrlread($a, 1)) AND GUICtrlread($a) = 1 Then Thanks! its solved now Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this: Spoiler #1. I am a native French speaker and learned English mainly from chatting with others players in online games. #2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor. ~WilliamasKumeliukas
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now