Sign in to follow this  
Followers 0
GodForsakenSoul

more ini issues....

6 posts in this topic

#include "Include\GuiConstants.au3"
#include "Include\GuiConstantsEx.au3"
#include "Include\ButtonConstants.au3"
#include "Include\EditConstants.au3"

Func GUIMainGui()
    GUICreate("Japanese basic training",350,250)
    Opt("GuiCoordMode",0)
    $mbutton1=GUICtrlCreateButton("Practice Kana",50,50,100,20)
    $mbutton2=GUICtrlCreateButton("Practice Conjucation",0,30,150,20)
    $mbutton3=GUICtrlCreateButton("Options",0,30,150,20)
    $mbutton4=GUICtrlCreateButton("Exit",0,100,150,20)
    GUISetState()

    while 1=1
        $mgmsg=GUIGetMsg()
        Select
            Case $mgmsg=$mbutton1
                IniWrite("Data\OPT.INI","OPTIONS","BUTTONMG","1")
                Sleep(10)
                ExitLoop
            Case $mgmsg=$mbutton2
                IniWrite("Data\OPT.INI","OPTIONS","BUTTONMG","2")
                Sleep(10)
                ExitLoop
            Case $mgmsg=$mbutton3
                IniWrite("Data\OPT.INI","OPTIONS","BUTTONMG","3")
                Sleep(10)
                ExitLoop
            Case $mgmsg=$mbutton4
                IniWrite("Data\OPT.INI","OPTIONS","BUTTONMG","4")
                Sleep(10)
                ExitLoop
            Case $mgmsg=$GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd
EndFunc

Func GUIPKAN()
    GUICreate("Japanese basic training: Kana training",300,200)
    Opt("GuiCoordMode",0)
    $pkanradio1=GUICtrlCreateRadio("Hiragana only",25,25,150,20)
    $pkanradio2=GUICtrlCreateRadio("Katakana only",0,20,150,20)
    $pkanradio3=GUICtrlCreateRadio("Both",0,20,150,20)
    GUICtrlCreateLabel("How many letters would you like to go through?",-20,30,200,30)
    $pkaninput1=GUICtrlCreateInput("",20,30,150,20,$ES_NUMBER)
    $pkanbutton1=GUICtrlCreateButton("Start",30,20,100,20)
    GUISetState()

    while 1=1
        $pkanradr1=GUICtrlRead($pkanradio1)
        $pkanradr2=GUICtrlRead($pkanradio2)
        $pkanradr3=GUICtrlRead($pkanradio3)
        $pkanmsg=GUIGetMsg()
        Select
            Case $pkanmsg=$pkanbutton1
                Select
                    Case $pkanradr1=$GUI_CHECKED
                        IniWrite("Data\OPT.INI","OPTIONS","KANASET","1")
                    Case $pkanradr2=$GUI_CHECKED
                        IniWrite("Data\OPT.INI","OPTIONS","KANASET","2")
                    Case $pkanradr3=$GUI_CHECKED
                        IniWrite("Data\OPT.INI","OPTIONS","KANASET","3")
                EndSelect
            Case $pkanmsg=$GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd
EndFunc

#include "Data\GUIMAINGUI.au3"
FileOpen("Data\OPT.INI",1)
$inir1=IniRead("Data\OPT.INI","OPTIONS","BUTTONMG","0")
GUIMainGui()
Select
    Case $inir1=1
        GUIPKAN()
    Case $inir1=2
        Sleep(10)
    Case $inir1=3
        Sleep(10)
    Case $inir1=4
        Exit
EndSelect

i somehow messed up the earlier version and decided it's best i start over. again, similar, if not same two files.

this time i'm having a new problem i didn't have earlier: it doesn't change the values in the ini file fast enough or something.

basically, it remembers the previous choice for one "turn". so i have to run the thing twice. earlier i didn't have to do this.

i know this code is far from good. i'll do my best to perfect it soon enough.

Share this post


Link to post
Share on other sites



FileOpen returns a handle to the opened file.

This allows you to do neat things like create the file if it doesn't exist, faster accessing when the handle is left open etc... but, it is rendered useless unless you point it to the handle... so revise your script sonnn try this?

$hwnd = FileOpen("Data\OPT.INI",1)

$inir1=IniRead($hwnd,"OPTIONS","BUTTONMG","0")

try that?

Share this post


Link to post
Share on other sites

no, no, you don't seem to understand.

the problem is that for some reason the ini update is now loads slower.

god knows why....

Share this post


Link to post
Share on other sites

create your INI file at the beginning of your script if the INI does not already exist. Use a function to do it. From looking t your code, you have sleep in a function that does nothing. DON'T DO THAT! All that does is slow your script down. Use consolewrite if you need to see what your script is doing if you are trying to keep track.

Share this post


Link to post
Share on other sites

It's kinda of hard to understand what you're trying to achieve, looking at your script.

Basically you're trying to make a Japanese Hiragana/Katakana trainer right?

Why do you want to write to the INI at all?

As it stands, everything is a mess.

Why are you using two .au3 files?

Why aren't you just calling the function for the user when they click a button?

Let me show you an example:

#include "GuiConstants.au3"
#include "GuiConstantsEx.au3"
#include "ButtonConstants.au3"
#include "EditConstants.au3"

$hGUIMainGui = GUICreate("Japanese basic training", 350, 250)
Opt("GuiCoordMode", 0)
$mbutton1 = GUICtrlCreateButton("Practice Kana", 50, 50, 100, 20)
$mbutton2 = GUICtrlCreateButton("Practice Conjucation", 0, 30, 150, 20)
$mbutton3 = GUICtrlCreateButton("Options", 0, 30, 150, 20)
$mbutton4 = GUICtrlCreateButton("Exit", 0, 100, 150, 20)
GUISetState()

While 1
    $mgmsg = GUIGetMsg()
    Switch $mgmsg
        Case $mbutton1
            GUISetState(@SW_HIDE, $hGUIMainGui) ;Hide current (main) GUI to prevent cluttering of the screen
            GUIPKAN() ; Call function to create new GUI (to practise kana)

        Case $mbutton2
            ; put code here to call or create a GUI to Practise Conjucation

        Case $mbutton3
            ; put code here to call or create an options GUI

        Case $mbutton4
            Exit ; Just shutdown the program..

        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func GUIPKAN()
    Local $KANASET = 1 ; Initialize KANASET variable and set default option.
    Local $hGUIPKAN = GUICreate("Japanese basic training: Kana training", 300, 200)
    Opt("GuiCoordMode", 0)

    $pkanradio1 = GUICtrlCreateRadio("Hiragana only", 25, 25, 150, 20)
    $pkanradio2 = GUICtrlCreateRadio("Katakana only", 0, 20, 150, 20)
    $pkanradio3 = GUICtrlCreateRadio("Both", 0, 20, 150, 20)
    GUICtrlCreateLabel("How many letters would you like to go through?", -20, 30, 200, 30)
    $pkaninput1 = GUICtrlCreateInput("0", 20, 30, 150, 20, $ES_NUMBER)
    $pkanbutton1 = GUICtrlCreateButton("Start", 30, 20, 100, 20)

    GUICtrlSetState($pkanradio1, $GUI_CHECKED) ; Set pkanradio1 as the default Radio button.
    ;We could also do a Switch ReadIni() ... Case ... EndSwitch here to determine a previous choice by the user.
    ; If that's what your goal was.

    GUISetState()

    While 1
        $pkanmsg = GUIGetMsg()

        Switch $pkanmsg
            Case $pkanbutton1
                ; The user wants to start!
                ; Let's use the information we have gathered to provide what the user wants.
                MsgBox(0, "Starting...", "You have picked KANASET: " & $KANASET & @CRLF & "Amount of characters: " & GUICtrlRead($pkaninput1))
                Switch $KANASET
                    Case 1
                        MsgBox(0, "Running", "Hiragana only!")
                        ;Call a function with a parameter maybe?
                    Case 2
                        MsgBox(0, "Running", "Katakana only!")
                        ;Call a function with a parameter maybe?
                    Case 3
                        MsgBox(0, "Running", "Both!")
                        ;Call a function with a parameter maybe?
                EndSwitch

            Case $pkanradio1
                ; Radio button got pressed, so it's safe to assume that it's $GUI_CHECKED. Thus we set $KANASET to 1, no need to write to an ini.
                ; ofcourse we still could at this point, just a case of adding more code.
                $KANASET = 1

            Case $pkanradio2
                $KANASET = 2

            Case $pkanradio3
                $KANASET = 3

            Case $GUI_EVENT_CLOSE
                GUIDelete($hGUIPKAN) ; Delete the GUI, you don't need it anymore.
                GUISetState(@SW_SHOW, $hGUIMainGui) ; Unhide Main GUI
                ExitLoop ; Exit the current while loop to get back into the MAIN GUI's loop.
        EndSwitch
    WEnd
EndFunc

Now I kinda gave your code an overhaul, but it should at least give you a nudge towards the right way.

I put in comments on what I did and where you can put in some code to write to an INI if you're still set on that.

As far as I'm concerned though, I'd suggest you'd focus on getting a working program first.

Before going into saving users preferences and such. Especially in a program such as this, which really doesn't need any saved preferences (It's just a couple of button clicks after 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