Chimaera

Looping through checkboxes with a second command on each?

8 posts in this topic

I have a button on a small gui with 30 checkboxes that starts the final process

The checkboxes contain install switches like this

[settings1]
ms1= -a
ms2= -d
ms3= -e
ms4= -er

Doing this works

If GUICtrlRead($MainCheckbox1) = $GUI_CHECKED Then
                    $SwitchCheck = IniRead(@ScriptDir & "\settings.ini", "settings1", "ms1", "")
                    $AddSwitches &= ' ' & $SwitchCheck
                EndIf
                If GUICtrlRead($MainCheckbox2) = $GUI_CHECKED Then
                    $SwitchCheck = IniRead(@ScriptDir & "\settings.ini", "settings1", "ms2", "")
                    $AddSwitches &= ' ' & $SwitchCheck
                EndIf

But i wanted to automate it so it just loops through and collects all the needed switches

So i came up with this but its not showing the switches

For $n = $MainCheckbox1 To $MainCheckbox30
                        GUICtrlRead($MainCheckbox + $n, $GUI_CHECKED)
                    $SwitchCheck = IniRead(@ScriptDir & "\settings.ini", "settings1", "ms" + $n , "")
                    $AddSwitches &= ' ' & $SwitchCheck
                    Next

Any pointers where i have gone wrong please?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

For $n = 1 To 30   
      If GUICtrlRead(Eval("MainCheckbox" & $n) = $GUI_CHECKED Then
          $SwitchCheck = IniRead(@ScriptDir & "\settings.ini", "settings1", "ms" & $n , "")
          $AddSwitches &= ' ' & $SwitchCheck
     EndIf
Next

Be careful with the meaning of variables

Edited by mikell

Share this post


Link to post
Share on other sites

When creating the checkboxes assign the returned IDs to an array and then loop through this array.


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

im holding water's suggestion in reserve atmo until i have worn out mikell's

Onwards another thought, i have set an IniWrite on every time a checkbox is selected so the gui remembers whats done

but it gives a perceptable lurch whilst it is doing the writing .

Am i better to save them to the button at the end so it saves them all as one hit or do a little each time?

i dont want the end to have a huge lurch either really...

Share this post


Link to post
Share on other sites

What do you mean by "perceptable lurch"? Half a second, a second?


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

#6 ·  Posted (edited)

hard to explain

you click the checkbox and the lurch happens so it makes you want to click it again cos you think you didnt catch it.

half a sec maybe before the tick appears

the code to check it is like this

Case $MainCheckbox2
    If GUICtrlRead($MainCheckbox2) = $GUI_CHECKED Then
        IniWrite(@ScriptDir & "\settings.ini", "gui", "g2", "1")
        _UpdateGui()
        GUICtrlSetData($CurrentSettings, "Current Settings = tn.bat" & $AddSwitches)
    Else
        IniWrite(@ScriptDir & "\settings.ini", "gui", "g2", "0")
        _UpdateGui()
        GUICtrlSetData($CurrentSettings, "Current Settings = tn.bat" & $AddSwitches)
    EndIf
                
Func _UpdateGui()
    $AddSwitches = ''
    For $n = 1 To 30
        If GUICtrlRead(Eval("MainCheckbox" & $n)) = $GUI_CHECKED Then
            $SwitchCheck = IniRead(@ScriptDir & "\settings.ini", "main", "ms" & $n, "")
            $AddSwitches &= ' ' & $SwitchCheck
        EndIf
    Next
    For $n = 1 To 10
        If GUICtrlRead(Eval("SecondaryCheckbox" & $n)) = $GUI_CHECKED Then
            $SwitchCheck = IniRead(@ScriptDir & "\settings.ini", "secondary", "ss" & $n, "")
            $AddSwitches &= ' ' & $SwitchCheck
        EndIf
    Next
    ConsoleWrite(@ScriptDir & '\tn.bat' & $AddSwitches & @CRLF)
    Return $AddSwitches
EndFunc   ;==>_UpdateGui

The way ive got it set it updates the Gui at every turn as things change

Edited by Chimaera

Share this post


Link to post
Share on other sites

You are doing a lot of processing (CtrlRead and IniRead plus the Eval statements) so I think half a second isn't too bad.


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