Jump to content

[Solved] find which radio is checked and writing to ini file


Recommended Posts

I need to find which button is checked and write to an inifile, I got this far before I became confused to how I could get to the answer, I thought of doing a seperate IF statements with GUICtrlRead, but was still unsure of how to get the answer, this is what I have so

$mygui = GUICreate("My GUI")
$Group1 = GUICtrlCreateGroup("Mode", 392, 16, 169, 121)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$firstmode = GUICtrlCreateRadio("First Mode", 408, 40, 73, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$secondmode = GUICtrlCreateRadio("Second Mode", 408, 64, 73, 17)
$firsecmode = GUICtrlCreateRadio("First and Second Mode", 408, 88, 113, 17)
$thirdmode = GUICtrlCreateRadio("Third Mode", 408, 112, 97, 17)

IniWrite($currentsettings, "Functionsettings", "Mode", ?)

Edit: NVM, I was looking at the help file under GUIGetMsg, and was able to form the code I need from that example

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

If you want them to return a number for the value then there are a couple of easy ways that you can use. I'll start the numbering at 0 (first mode) for simplicity.

First you should be using an INI read when the script loads

$iMode = IniRead($currentsettings, "Functionsettings", "Mode", 0)

Remove the line

GUICtrlSetState(-1, $GUI_CHECKED)

Instead, after the last Radio control add the line

GUICtrlSetState($firstmode + $iMode, $GUI_CHECKED)

Now in the Message Loop and assuming you are using a Switch statement instead of a Select, add a Case statement

Case $firstmode To $thirdmode
    $iMode = $Msg - $firstmode
    IniWrite($currentsettings, "Functionsettings", "Mode", $iMode)

Now You should have something like

$iMode = IniRead($currentsettings, "Functionsettings", "Mode", 0)
$mygui = GUICreate("My GUI")
$Group1 = GUICtrlCreateGroup("Mode", 392, 16, 169, 121)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$firstmode = GUICtrlCreateRadio("First Mode", 408, 40, 73, 17)
$secondmode = GUICtrlCreateRadio("Second Mode", 408, 64, 73, 17)
$firsecmode = GUICtrlCreateRadio("First and Second Mode", 408, 88, 113, 17)
$thirdmode = GUICtrlCreateRadio("Third Mode", 408, 112, 97, 17)
GUICtrlSetState($firstmode + $iMode, $GUI_CHECKED)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
       Case $GUI_EVENT_CLOSE
           Exit
       Case $firstmode To $thirdmode
           $iMode = $Msg - $firstmode
           IniWrite($currentsettings, "Functionsettings", "Mode", $iMode)
    EndSwitch
Wend

And, unless I messed up writing this on the fly, it should do what you want.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

First you should be using an INI read when the script loads

$iMode = IniRead($currentsettings, "Functionsettings", "Mode", 0)

I'm actually trying to write the mode into an ini file on this script, I have another script that will read it.

I tried the rest your example earlier when I came accross something similar in the help file, but could not get it to do what I need. for what I need is for the key to be set as the button chosen ie: First, Second, Third.

so i written something like this:

While 1
    $Msg = GUIGetMsg()
    Select $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $msg = $firstmode
            $mode = "First Mode"
        Case $msg = $secondmode
            $mode = "Second Mode"
        Case $msg = $firsecmode
            $mode = "First and Second Mode"
        Case $msg = $thirdmode
            $mode = "Third Mode"
    EndSelect
    IniWrite($currentsettings, "Functionsettings", "Mode", $mode)
Wend

I'm bit of Noob, I'm sure you can tell! with your example, it seems that sum type of number assignment has to be set to the keys

in order for it to work, correct me if I'm wrong. I just could'nt get it to work my way with that format, but this seems to work.

What is the difference between Select and Switch, again correct me if I'm wrong, a Switch will cease after its first call, but

Select will allow more calls to made?

Edit: my code example had bad format, fixed it

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

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