Jump to content

Ini read help please


SunnBoy
 Share

Recommended Posts

Hey guys,

I just started a script for a Spanish Vocabulary learn helper :(

Now i got a little problem with my script.

Here it is

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\Marvin\Desktop\Ch1.kxf
$Form1 = GUICreate("Chapter 1", 258, 331, 192, 124)
$Label = GUICtrlCreateLabel("Chapter 1", 64, 8, 129, 46)
GUICtrlSetFont(-1, 18, 400, 0, "Segoe Print")
$Label1 = GUICtrlCreateLabel("Spanish to English", 40, 48, 182, 37)
GUICtrlSetFont(-1, 14, 400, 0, "Segoe Print")
$Label2 = GUICtrlCreateLabel("Word 1", 8, 96, 55, 27)
GUICtrlSetFont(-1, 10, 400, 0, "Segoe Print")
$Label3 = GUICtrlCreateLabel("Word 2", 8, 136, 55, 27)
GUICtrlSetFont(-1, 10, 400, 0, "Segoe Print")
$Label4 = GUICtrlCreateLabel("Word 3", 8, 176, 55, 27)
GUICtrlSetFont(-1, 10, 400, 0, "Segoe Print")
$Input1 = GUICtrlCreateInput("", 112, 96, 121, 21)
$Input2 = GUICtrlCreateInput("", 112, 136, 121, 21)
$Input3 = GUICtrlCreateInput("", 112, 176, 121, 21)
$Button1 = GUICtrlCreateButton("Submit Answers", 48, 216, 139, 73, $WS_GROUP)
$Read1 = GUICtrlRead ($Input1)
$Read2 = GUICtrlRead ($Input2)
$Read3 = GUICtrlRead ($Input3)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Submit_Answers ()

    EndSwitch
WEnd

Func Submit_Answers ()
$Read1 = GUICtrlRead ($Input1)
IniWrite ("Chapter1.ini","section1","Word1",$Read1)
$Read2 = GUICtrlRead ($Input2)
IniWrite ("Chapter1.ini","section2","Word2",$Read2)
$Read3 = GUICtrlRead ($Input3)
IniWrite ("Chapter1.ini","section3","Word3",$Read3)
$var = IniRead ("Ch1Answers.ini","section1","Word1","") + IniRead ("Ch1Answers.ini","section2","Word2","")
If $var = $Read1 then
    MsgBox (0,"Right","Correct Answer")
Else
    MsgBox (0,"Wrong","Wrong Answer")
EndIf

EndFunc

Now i have the file Ch1Answers.ini in my folder.

I want the script when someone puts the answers in to check the Answers file if the entered words are correct.

That worked fine, but then I added the part + IniRead ("Ch1Answers.ini","section2","Word2","") so i thought the script would check section2 also.

But its not really working maybe you guys can help me.

Would I have to do a

If $var = $Read1 then
    MsgBox (0,"Right","Correct Answer")
Else
    MsgBox (0,"Wrong","Wrong Answer")
EndIf

EndFunc

for every Word?

Or can i just put one for all?

Thanks :)

Edited by SunnBoy
Link to comment
Share on other sites

  • Moderators

SunnBoy,

Does this help? I am assuming that you get your 3 answers from 3 ini files to match the IniWrite ones. If you want to check all 3 at once, you need to concatenate the 3 responses and the the 3 answers like this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#region ### START Koda GUI section ### Form=C:\Users\Marvin\Desktop\Ch1.kxf
$Form1 = GUICreate("Chapter 1", 258, 331, 192, 124)
$Label = GUICtrlCreateLabel("Chapter 1", 64, 8, 129, 46)
GUICtrlSetFont(-1, 18, 400, 0, "Segoe Print")
$Label1 = GUICtrlCreateLabel("Spanish to English", 40, 48, 182, 37)
GUICtrlSetFont(-1, 14, 400, 0, "Segoe Print")
$Label2 = GUICtrlCreateLabel("Word 1", 8, 96, 55, 27)
GUICtrlSetFont(-1, 10, 400, 0, "Segoe Print")
$Label3 = GUICtrlCreateLabel("Word 2", 8, 136, 55, 27)
GUICtrlSetFont(-1, 10, 400, 0, "Segoe Print")
$Label4 = GUICtrlCreateLabel("Word 3", 8, 176, 55, 27)
GUICtrlSetFont(-1, 10, 400, 0, "Segoe Print")
$Input1 = GUICtrlCreateInput("", 112, 96, 121, 21)
$Input2 = GUICtrlCreateInput("", 112, 136, 121, 21)
$Input3 = GUICtrlCreateInput("", 112, 176, 121, 21)
$Button1 = GUICtrlCreateButton("Submit Answers", 48, 216, 139, 73, $WS_GROUP)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Submit_Answers()

    EndSwitch
WEnd

Func Submit_Answers()

    $Read1 = GUICtrlRead($Input1)
    IniWrite("Chapter1.ini", "section1", "Word1", $Read1)
    $Read2 = GUICtrlRead($Input2)
    IniWrite("Chapter1.ini", "section2", "Word2", $Read2)
    $Read3 = GUICtrlRead($Input3)
    IniWrite("Chapter1.ini", "section3", "Word3", $Read3)

    ; Concatenate the responses
    $Response = $Read1 & $Read2 & $Read3

    ; Concatenate the answers
    $var =  IniRead("Ch1Answers.ini", "section1", "Word1", "") & _
            IniRead("Ch1Answers.ini", "section2", "Word2", "") & _
            IniRead("Ch1Answers.ini", "section3", "Word3", "")

    ; If all correct say so
    If $var = $Response Then
        MsgBox(0, "Right", "Correct Answer")
    Else
        MsgBox(0, "Wrong", "Wrong Answer")
    EndIf

EndFunc   ;==>Submit_Answers

I hope that helps. If not, please post some truncated ini files so we can see the structure a bit better. :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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