Sign in to follow this  
Followers 0
Rogue5099

For Loop for my controls

5 posts in this topic

#1 ·  Posted (edited)

I want to make the following checkboxes into an array. I know I could just do Checkbox[1], Checkbox[2] but I would like to simplify it to a loop.

$Checkbox1 = GUICtrlCreateCheckbox("1", 240, 136, 33, 17)
$Checkbox2 = GUICtrlCreateCheckbox("2", 280, 136, 33, 17)
$Checkbox3 = GUICtrlCreateCheckbox("3", 240, 160, 33, 17)
$Checkbox4 = GUICtrlCreateCheckbox("4", 280, 160, 33, 17)
$Checkbox5 = GUICtrlCreateCheckbox("5", 240, 184, 33, 17)
$Checkbox6 = GUICtrlCreateCheckbox("6", 280, 184, 33, 17)
$Checkbox7 = GUICtrlCreateCheckbox("7", 240, 208, 33, 17)
$Checkbox8 = GUICtrlCreateCheckbox("8", 280, 208, 33, 17)

My problem is the 240-280 and the 2x 136, 160, 184 other wise i could just do 136+24

EDIT:

Ok so far I have gotten this far on my own:

For $i = 1 To 8
    If Mod($i, 2) = 0 Then
        $Checkbox[$i] = GUICtrlCreateCheckbox($i, 280, 136, 33, 17)
    Else
        $Checkbox[$i] = GUICtrlCreateCheckbox($i, 240, 136, 33, 17)
    EndIf
Next
Edited by rogue5099

Share this post


Link to post
Share on other sites



rogue5099,

I will let you work out how I did it: :mellow:

#include <GUIConstantsEx.au3>

Global $aCheck[8]

$hGUI = GUICreate("Test", 500, 500)

For $i = 0 To 3
    For $j = 0 To 1
        $aCheck[($i * 2) + $j] = GUICtrlCreateCheckbox(($i * 2) + $j + 1, 240 + (40 * $j), 136 + (24 * $i), 33, 17)
    Next
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    Case $aCheck[0] To $aCheck[7]
            ConsoleWrite("You actioned Checkbox " & $iMsg - $aCheck[0] + 1 & @CRLF)
    EndSwitch
WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here the one liner loop from M23's example :mellow: :

For $i = 0 To 7
    $aCheck[$i] = GUICtrlCreateCheckbox($i + 1, 240 + Mod($i, 2) * 40, 136 + ($i + 1 + Floor(Mod($i + 1, 2) - 2)) * 12, 33, 17)
Next

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

UEZ,

And :mellow::) back to you! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
Sign in to follow this  
Followers 0