Sign in to follow this  
Followers 0
Queener

Search string in Ini Sections

8 posts in this topic

#1 ·  Posted (edited)

So on my ini file I have as follow:

 

[1]

Name=1

Q=What is a fastest way to get to command prompt?

M1=start->run->cmd

M2=hold winkey then press r key then type cmd

M3=press win key then type cmd

A=B

[2]

Name=2

etc...

 

 

 

 

 

 

On my interface, I have a label, 3 radios, and a button. What I'm trying to do is on the label, it contain the question, I want to find what is the section name of the question. I haven't try anything yet because I'm stuck on how I'm supposed to go about doing so.

 

Ex:

On my label, it contain the question: What is a fastest way to get to command prompt?

If I press the button, it will prompt me a message, "This question is located in section 1"

 

Thanks in advance

Edited by Queener

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

that seems like scratching your left ear with your right hand over your head. your script did write the label, didn't it? so you must know from which section that label was taken, because you took it from there. so, when you build the GUI, just put the section name in a variable for later use.

and yes, there are pretty simple methods to do what you want by directly accessing the ini file. hardly as efficient as just remembering the section name when you read it.

Edited by orbs

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It's hard to explain in words, but the reason I want to do a string search is because when I click the submit button, it determine the correct answer then go onto the next question. I got the next question display correctly, but when it determine the correct answer, it uses the first question answer. So if I do a string search on the section, it would look for the section answer instead of a static number that I put. Here's my real code for the portion:

 

;some variables to ini
$QS = 1 ;This is where I want to compare the string to the section!



$Exam1_ID = GUICtrlRead($CExam)
$Exam1_Loc = @ScriptDir & "\assets\" & $Exam1_ID & ".ini"
$Exam1_Counter = IniRead($Exam1_Loc, "counter", "code", "Default")
$Exam1_Quest = IniRead($Exam1_Loc, $QS, $QS, "default")
$Exam1_R1 = IniRead($Exam1_Loc, $QS, "M1", "default")
$Exam1_R2 = IniRead($Exam1_Loc, $QS, "M2", "default")
$Exam1_R3 = IniRead($Exam1_Loc, $QS, "M3", "default")
$Exam1_R4 = IniRead($Exam1_Loc, $QS, "M4", "default")
$Exam1_R5 = IniRead($Exam1_Loc, $QS, "M5", "default")
$Exam1_AN = IniRead($Exam1_Loc, $QS, "A", "default")

;check answers then reload new questions
If GUICtrlRead($r1) = $GUI_CHECKED Then
    if GUICtrlRead($r1, 1) = $Exam1_AN Then
        MsgBox(0, "Correct", "You're Correct!", 5)
        NextQues()
    Else
        MsgBox(0, "Wrong", "The correct answer is - " & $Exam1_AN)
    EndIf
EndIf

If GUICtrlRead($r2) = $GUI_CHECKED Then
    if GUICtrlRead($r2, 1) = $Exam1_AN Then
        MsgBox(0, "Correct", "You're Correct!", 5)
        NextQues()
    Else
        MsgBox(0, "Wrong", "The correct answer is - " & $Exam1_AN)
    EndIf
EndIf

If GUICtrlRead($r3) = $GUI_CHECKED Then
    if GUICtrlRead($r3, 1) = $Exam1_AN Then
        MsgBox(0, "Correct", "You're Correct!", 5)
        NextQues()
    Else
        MsgBox(0, "Wrong", "The correct answer is - " & $Exam1_AN)
    EndIf
EndIf

If GUICtrlRead($r4) = $GUI_CHECKED Then
    if GUICtrlRead($r4, 1) = $Exam1_AN Then
        MsgBox(0, "Correct", "You're Correct!", 5)
        NextQues()
    Else
        MsgBox(0, "Wrong", "The correct answer is - " & $Exam1_AN)
    EndIf
EndIf

If GUICtrlRead($r5) = $GUI_CHECKED Then
    if GUICtrlRead($r5, 1) = $Exam1_AN Then
        MsgBox(0, "Correct", "You're Correct!", 5)
        NextQues()
    Else
        MsgBox(0, "Wrong", "The correct answer is - " & $Exam1_AN)
    EndIf
EndIf

 

 

 

 

Edited by Queener

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites

that is a horrid approach to coding a quiz. but first thing first - how does NextQues() look like?

BTW when you post code to the forum, use the code tags - that's the  < >  toolbar icon.

Share this post


Link to post
Share on other sites

Your script must know the correct answer in same moment as question is shown. All other is like:

18 minutes ago, orbs said:

that seems like scratching your left ear with your right hand over your head. your script did write the label, didn't it? so you must know from which section that label was taken, because you took it from there.

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I can assure you that if I can do a search to know the $QS number which is the section number then the rest is a piece of cake.

 

 

;This will reform the next question for you!
;some variables to ini

$QS = "1"
$QS = $QS + 1

$Exam1_ID = GUICtrlRead($CExam)
$Exam1_Loc = @ScriptDir & "\assets\" & $Exam1_ID & ".ini"
$Exam1_Counter = IniRead($Exam1_Loc, "counter", "code", "Default")
$Exam1_Quest = IniRead($Exam1_Loc, $QS, $QS, "default")
$Exam1_R1 = IniRead($Exam1_Loc, $QS, "M1", "default")
$Exam1_R2 = IniRead($Exam1_Loc, $QS, "M2", "default")
$Exam1_R3 = IniRead($Exam1_Loc, $QS, "M3", "default")
$Exam1_R4 = IniRead($Exam1_Loc, $QS, "M4", "default")
$Exam1_R5 = IniRead($Exam1_Loc, $QS, "M5", "default")
$Exam1_AN = IniRead($Exam1_Loc, $QS, "A", "default")

;empty out select radio
GUICtrlSetState($R1, $GUI_UNCHECKED)
GUICtrlSetState($R2, $GUI_UNCHECKED)
GUICtrlSetState($R3, $GUI_UNCHECKED)
GUICtrlSetState($R4, $GUI_UNCHECKED)
GUICtrlSetState($R5, $GUI_UNCHECKED)

;Set Question Box
GUICtrlSetData($GQuestion, "Question " & $QS)
;Set questions
GUICtrlSetData($LQuestions, $Exam1_Quest)
;set radios -> also need to check and see if additional radio is needed.
GUICtrlSetData($R1, $Exam1_R1)
GUICtrlSetData($R2, $Exam1_R2)
GUICtrlSetData($R3, $Exam1_R3)
GUICtrlSetData($R4, $Exam1_R4)

 

Nevermind, I found a quicker solution:

I used

 

$QS = StringReplace(StringRight(GUICtrlRead($GQuestion),2), " ", "")

 

 

 

 

 

Edited by Queener
Solved

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites
14 minutes ago, Queener said:

I can assure you that if I can do a search to know the $QS number which is the section number then the rest is a piece of cake.

that is incorrect. that will be the first of a long series of problems you are facing.

what you need to do is reconstruct your script, something along these lines:

_BuildGUIWithEmptyLabelsAndRadios()

Global $aSection = IniReadSectionNames('your_ini_file.ini')
Global $iSection = 1
Global $msg = 0

While True
    $aQuestion = IniReadSection('your_ini_file.ini', $aSection[$iSection])
    _PopulateLabelAndRadios($aQuestion)
    While True
        $msg = GUIGetMsg()
        If $msg = $idSubmitButton Then
            If _AnswerCorrect() Then
                ; msgbox for correct answer
                $iSection += 1
                ContinueLoop 2
            Else
                ; msgbox for incorrect answer
            EndIf
        EndIf
    WEnd
    ; msgbox for cquiz ompleted successfully
WEnd

look at the help for IniReadSectionNames() and IniReadSection().

i'll leave you to put your current code into the unspecified functions mentioned in the script.

sorry if it sounds like too much work, but that's actually the better way, both short and long term.

Share this post


Link to post
Share on other sites

I'll take your consideration in place if I'm facing problem, but it seems to work so far :) A little more tweaks to the whole script. I notice that if I get the wrong answer; it stops going to the next question so I tweaked that also.


Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
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
Sign in to follow this  
Followers 0