Jump to content

Read controlID from INI file


Recommended Posts

Hello

I can't understand why i can't read controlID from .ini file

i have simple code

#include <GUIConstantsEx.au3>
$Radio_click=IniRead("click_ini.ini", "radios", "Radio_1 ","error")

Example()

Func Example()
        GUICreate("My GUI group") ; will create a dialog box that when displayed is centered

        GUICtrlCreateGroup("Group 1", 190, 60, 90, 140)
        $1=GUICtrlCreateRadio("Radio1", 210, 90, 50, 20)
        $2=GUICtrlCreateRadio("Radio2", 210, 120, 60, 50)
        $3=GUICtrlCreateRadio("Radio3", 210, 150, 70, 80)
        GUICtrlSetState($1,1)
        GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group 1

        GUISetState(@SW_SHOW) ; will display an empty dialog box

        ; Loop until the user exits.
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                EndSwitch
        WEnd
EndFunc   ;==>Example

When I want set Radio1 to be checked i write GUICtrlSetState($1,1). In resul Radio1 is checked. But when i want read this controlID from .ini file changing GUICtrlSetState($1,1) to GUICtrlSetState($Radio_click,1) Radio1 is not checked . Where is my fault?

In .ini file i have

[radios]
Radio_1 =$1

 

Link to comment
Share on other sites

Instead of writing the variable ($1) to the ini, you need to write the checked state 1 or 4 ($GUI_CHECKED, $GUI_UNCHECKED).

#include <GUIConstantsEx.au3>
$Radio_click=IniRead("click_ini.ini", "radios", "Radio_1 ","error")

Example()

Func Example()
        GUICreate("My GUI group") ; will create a dialog box that when displayed is centered

        GUICtrlCreateGroup("Group 1", 190, 60, 90, 140)
        $1=GUICtrlCreateRadio("Radio1", 210, 90, 50, 20)
        $2=GUICtrlCreateRadio("Radio2", 210, 120, 60, 50)
        $3=GUICtrlCreateRadio("Radio3", 210, 150, 70, 80)
        GUICtrlSetState($1, $Radio_click)
        GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group 1

        GUISetState(@SW_SHOW) ; will display an empty dialog box

        ; Loop until the user exits.
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                EndSwitch
        WEnd
EndFunc   ;==>Example
[radios]
Radio_1 =1

 

Link to comment
Share on other sites

 

Execute doesn't work. The idea is control radio button in group of buttons from ini. file.  So if i change GUICtrlSetState($1, $Radio_click) to GUICtrlSetState($Radio_click,1) i will be able to control only first radio1 state but i want control which radio will be checked in group.

Link to comment
Share on other sites

clarification

#include <GUIConstantsEx.au3>

;~ [radios]
;~ Radio_1=$R1

$Radio_click = "$R1" ;IniRead("click_ini.ini", "radios", "Radio_1 ","error")

Example()


Func Example()
        GUICreate("My GUI group") ; will create a dialog box that when displayed is centered

        GUICtrlCreateGroup("Group 1", 190, 60, 90, 140)
        $R1=GUICtrlCreateRadio("Radio1", 210, 90, 50, 20)
        ConsoleWrite("$R1=" & $R1 & @CRLF)
        $R2=GUICtrlCreateRadio("Radio2", 210, 120, 60, 50)
        $R3=GUICtrlCreateRadio("Radio3", 210, 150, 70, 80)

        ConsoleWrite("$Radio_click=" & $Radio_click & @CRLF)
        ConsoleWrite("Execute($Radio_click)=" & Execute($Radio_click) & @CRLF)

        GUICtrlSetState(Execute($Radio_click),1)

        GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group 1

        GUISetState(@SW_SHOW) ; will display an empty dialog box

        ; Loop until the user exits.
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                EndSwitch
        WEnd
EndFunc   ;==>Example

I know that I know nothing

Link to comment
Share on other sites

IniRead returns a String, but GUICtrlSetState requires a ControlID which IIRC is an integer. So

GUICtrlSetState(Int($Radio_click), ...)

should work (untested).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

11 minutes ago, water said:

should work

No it won't.  The ini file contains the name of the variable (e.g. "$1"), not the actual control id value (which would be a very bad idea).  So we need to run Execute to translate it into a valid control id.

5 hours ago, orok said:

Execute doesn't work

Of course it works.  Either you didn't use correctly or I don't understand your request...

Execute is required because of the dollar sign in front of the name, but this would also work :

GUICtrlSetState(Eval(StringTrimLeft($Radio_click, 1)),1)

 

Edited by Nine
Link to comment
Share on other sites

Why not write the state of all Radios to the Ini-File? Then read the needed key or all keys of the section and set the Control to the needed state.
No need to store the name of the variables nor the control-Ids as this is information already available in the script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Well since radio buttons are mutually exclusive, there is no need to write the state of all radios, you just want the one checked within each group.  I believe OP wants to have multiple groups of radio buttons.  So the ini file would list the one button checked within each group.  I agree there is other ways to perform what OP wants, and using actual names is not the best. 

Link to comment
Share on other sites

Posted (edited)

Yes it is as you wrote. With group with 2 radios i use numbers to set which of radios is checked. In group of 3 radios i can set only state one radio in group with numbers so tried to set state by other ways. Nothing above works unfortunately.

Edited by orok
Link to comment
Share on other sites

i would save and load the states of the radio buttons in this way:

#include <GUIConstantsEx.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 259, 111, 192, 124)
Global $radio[6]

GUICtrlCreateGroup("Group 1", 0, 0, 90, 110)
$radio[0] = GUICtrlCreateRadio("Radio0", 14, 19, 71, 20)
$radio[1] = GUICtrlCreateRadio("Radio1", 14, 46, 71, 20)
$radio[2] = GUICtrlCreateRadio("Radio2", 14, 72, 71, 20)
GUICtrlCreateGroup("", -1, -1, 0, 0)

GUICtrlCreateGroup("Group 2", 104, 0, 90, 110)
$radio[3] = GUICtrlCreateRadio("Radio0", 114, 19, 71, 20)
$radio[4] = GUICtrlCreateRadio("Radio1", 114, 46, 71, 20)
$radio[5] = GUICtrlCreateRadio("Radio2", 114, 72, 71, 20)
GUICtrlCreateGroup("", -1, -1, 0, 0)


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$state = Int(IniRead("radio.ini", "radiobutton", "1", 0))
$state1 = Int(IniRead("radio.ini", "radiobutton", "2", 0))

GUICtrlSetState($radio[$state], $gui_checked)
GUICtrlSetState($radio[$state1], $gui_checked)
WinSetTitle ($Form1,"","Rbutton: " & $state & "/" & $state1)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            For $x = 0 To 2
                If $nMsg > 0 And $nMsg = $radio[$x] Then
                    IniWrite("radio.ini", "radiobutton", "1", $x)
                    WinSetTitle ($Form1,"","Rbutton: " & $x)
                    $state=$x
                EndIf
            Next
            For $x = 3 To 5
                If $nMsg > 0 And $nMsg = $radio[$x] Then
                    IniWrite("radio.ini", "radiobutton", "2", $x)
                    $state1=$x
                EndIf
            Next
    EndSwitch
    WinSetTitle ($Form1,"","Rbutton: " & $state & "/" & $state1)
WEnd

 

Some of my script sourcecode

Link to comment
Share on other sites

I have found solution for my problem i tried to solve this with one value but if i use separate valule fo each radios in group its work

#include <GUIConstantsEx.au3>
$Radio_click1=IniRead("click_ini.ini", "radios", "Radio_1 ","error")
$Radio_click2=IniRead("click_ini.ini", "radios", "Radio_2 ","error")
$Radio_click3=IniRead("click_ini.ini", "radios", "Radio_3 ","error")

Example()

Func Example()
        GUICreate("My GUI group") ; will create a dialog box that when displayed is centered

        GUICtrlCreateGroup("Group 1", 190, 60, 90, 140)
        $R1=GUICtrlCreateRadio("Radio1", 210, 90, 50, 20)
        GUICtrlSetState(-1, $Radio_click1)
        $R2=GUICtrlCreateRadio("Radio2", 210, 120, 60, 50)
        GUICtrlSetState(-1, $Radio_click2)
        $R3=GUICtrlCreateRadio("Radio3", 210, 150, 70, 80)
        GUICtrlSetState(-1, $Radio_click3)
            
        GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group 1
        GUISetState(@SW_SHOW) ; will display an empty dialog box

        ; Loop until the user exits.
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                EndSwitch
        WEnd
EndFunc   ;==>Example

and in Ini file only one value can has 1.

[radios]
Radio_1           =1
Radio_2           =0
Radio_3           =0

Mixing 1 with 0 i can set radio which i want. For my purposes is enough. Thanks for your help!
 

 

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