# For Loop for my controls

## Recommended Posts

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

My projects:

##### Share on other sites

rogue5099,

I will let you work out how I did it:

```#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

Open spoiler to see 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 on other sites

Here the one liner loop from M23's example :

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

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

##### Share on other sites

UEZ,

And 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

Open spoiler to see 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 on other sites

Nice UZE and you too Melba23. I just dont have the brain power to come up with these algorithms!

My projects:

## Create an account

Register a new account