Onyinye

Indirect variables

4 posts in this topic

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. 

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Its 4 right now, but I'll probably add up to 10.  I realize I can just hard code each of them(that's what I have now), but I was trying to make the development easier for myself

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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