Jump to content

Indirect variables


Recommended Posts

I'm trying to Read read in a section of an ini with IniReadSection, then indirectly set GUI input boxes using inGUICtrlSetData using the variable name and data contained in the ini file.  

My ini file looks like this:
[GuiDefaultsInput]
$hGUIvariable1=123
$hGUIvariable2=1
$hGUIvariable3=2
$hGUIvariable4=3

All of the variables have already been defined using:

Global $hGUIvariable1=  GUICtrlCreateInput("test",10,350,100, 20)

I want to, in a loop, set the inputbox data to what is predefined in the ini file.Here is a snippet of my code:

;Assign input fields
$aIniRead = IniReadSection($iniPath,"GuiDefaultsInput")
For $i = 1 to $aIniRead[0][0]
    $result = GUICtrlSetData($aIniRead[$i][0],$aIniRead[$i][1])
    If $result = 0 then ExitProgram("Error setting Ini values in ReadIni() for input boxes. Trying to set variable:" &$aIniRead[$i][0] &" to "& $aIniRead[$i][1])
Next

I've also tried :

$result = GUICtrlSetData(GUICtrlGetHandle($aIniRead[$i][0]),$aIniRead[$i][1])

and

$result = GUICtrlSetData(String($aIniRead[$i][0]),$aIniRead[$i][1])

As well as various combinations of Eval() and Assign(). I feel like there is a command I'm missing to convert a String name to a variable name for somethting to evaluate. 

Link to comment
Share on other sites

How many variables are we talking about? Is it always $hGUIvariable1 to 4?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Up to 9 this works:

#include <GUIConstantsEx.au3>

GUICreate("Test", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1)
Global $iIDs[4]
$iIDs[0] = GUICtrlCreateInput("", 10, 5, 300, 20)
$iIDs[1] = GUICtrlCreateInput("", 10, 30, 300, 20)
$iIDs[2] = GUICtrlCreateInput("", 10, 55, 300, 20)
$iIDs[3] = GUICtrlCreateInput("", 10, 80, 300, 20)
_ReadIni()
GUISetState(@SW_SHOW)

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

Func _ReadIni()
    Local $aIni = IniReadSection(@ScriptDir & "\test.ini", "GuiDefaultsInput")
    For $i = 1 To $aIni[0][0]
        $iIndex = StringMid($aIni[$i][0], 14, 1) - 1
        If $iIndex >= 0 And $iIndex <= UBound($iIDs) - 1 Then GUICtrlSetData($iIDs[$iIndex], $aIni[$i][1])
    Next
EndFunc   ;==>_ReadIni

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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