Jump to content

For Next loop and ControlID's


Go to solution Solved by jugador,

Recommended Posts

I have tried many things to make this For/Next loop work. It always fails with the ControlID's
I assume it is going to fail when it reaches the final Function call too, but I haven't gotten that far yet.

Any assistance you're able to offer would be appreciated.

Global $Ini = @AppDataCommonDir & '\Test\settings.ini'

Global $Check1 = GUICtrlCreateCheckbox("Check1", 20, 20, 100, 20)
GUICtrlSetOnEvent(-1, 'Check1')
Global $Check2 = GUICtrlCreateCheckbox("Check2", 50, 20, 100, 20)
GUICtrlSetOnEvent(-1, 'Check2')
Global $Check3 = GUICtrlCreateCheckbox("Check3", 80, 20, 100, 20)
GUICtrlSetOnEvent(-1, 'Check3')
Global $Check4 = GUICtrlCreateCheckbox("Check4", 110, 20, 100, 20)
GUICtrlSetOnEvent(-1, 'Check4')

Func Check1()
    If GUICtrlRead($Check1) = 1 Then
        IniWrite($Ini, 'Current', "Check1", '1')
    Else
        IniWrite($Ini, 'Current', "Check1", '4')
    EndIf
EndFunc   ;==>Check1

Func Check2()
    If GUICtrlRead($Check2) = 1 Then
        IniWrite($Ini, 'Current', "Check2", '1')
    Else
        IniWrite($Ini, 'Current', "Check2", '4')
    EndIf
EndFunc   ;==>Check2

Func Check3()
    If GUICtrlRead($Check3) = 1 Then
        IniWrite($Ini, 'Current', "Check3", '1')
    Else
        IniWrite($Ini, 'Current', "Check3", '4')
    EndIf
EndFunc   ;==>Check3

Func Check4()
    If GUICtrlRead($Check4) = 1 Then
        IniWrite($Ini, 'Current', "Check4", '1')
    Else
        IniWrite($Ini, 'Current', "Check4", '4')
    EndIf
EndFunc   ;==>Check4

ArrStore('check')

Func ArrStore($strName)
    Local $arrNames[4] = ["Check1", "Check2", "Check3", "Check4"]
    If $strName = 'check' Then
        For $strName In $arrNames
            Local $var = _StringInsert($strName, '$', '1')
            If IniRead($Ini, 'Current', $strName, '4') = 4 Then
                GUICtrlSetState($var, 4)
            Else
                GUICtrlSetState($var, 1)
            EndIf
            $strName()
        Next
    EndIf
EndFunc   ;==>ArrStore

 

Edited by Shark007
Link to comment
Share on other sites

  • Developers

It would help when you post something that is runnable! ;) 

... but I would use an Array for the Controlhandles and simplify/shorten the logic. 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Solution

@Shark007 for GUICtrlSetState to work in your example use Execute

GUICtrlSetState(Execute($var), 4)

 

#include <String.au3>

Func Check1()
    ConsoleWrite('> Check1.....' & @CRLF)
EndFunc   ;==>Check1

Func Check2()
    ConsoleWrite('> Check2.....' & @CRLF)
EndFunc   ;==>Check2

Func Check3()
    ConsoleWrite('> Check3.....' & @CRLF)
EndFunc   ;==>Check3

Func Check4()
    ConsoleWrite('> Check4.....' & @CRLF)
EndFunc   ;==>Check4

ArrStore()
Func ArrStore()
    Local $var
    Local $arrNames[4] = ["Check1", "Check2", "Check3", "Check4"]
    For $strName In $arrNames
        $var = _StringInsert($strName, '$', 0)
        ;~~ GUICtrlSetState(Execute($var), 4)       ;~ <<<<= use Execute

        Execute($strName & '()') ;~ Method 1
        ;Call($strName)          ;~ Method 2
    Next
EndFunc   ;==>ArrStore

 

Edited by jugador
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...