Jump to content

Looping through checkboxes with a second command on each?


Chimaera
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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
Link to comment
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 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

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

Link to comment
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 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

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
Link to comment
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 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...