Jump to content

Creating checkbox elements in array


Go to solution Solved by Andreik,

Recommended Posts

Hi

I want to make array to store checkboxes inside so i can use it later in code for easier access, and for less code.

Issue is that loop is adding 1 more item in a row and there should be 5 rows and 5 columns, that's 25 in total.

Also it doesn't giving me correct box number like 1 - 25, instead i have 0-6, 0-6, 0-6

On images you can see valid one and invalid one.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ###
$Form1 = GUICreate("Form1", 341, 443, -1, -1)
$Group1 = GUICtrlCreateGroup("", 8, 40, 323, 361, -1, $WS_EX_TRANSPARENT)
$Tab1 = GUICtrlCreateTab(16, 64, 308, 329)
$TabSheet1 = GUICtrlCreateTabItem("Tab1")

Global $boxArray[5][25]

For $line = 0 To 4
    For $i = 0 To 24
        $boxArray[$line][$i] = GUICtrlCreateCheckbox('Box '&$i, 20+$i*59, 94+$line*58, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
    Next
Next

#cs
$box1 = GUICtrlCreateCheckbox("Box 1", 24, 94, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box2 = GUICtrlCreateCheckbox("Box 2", 83, 94, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box3 = GUICtrlCreateCheckbox("Box 3", 141, 94, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box4 = GUICtrlCreateCheckbox("Box 4", 199, 94, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box5 = GUICtrlCreateCheckbox("Box 5", 257, 94, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box6 = GUICtrlCreateCheckbox("Box 6", 24, 152, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box7 = GUICtrlCreateCheckbox("Box 7", 83, 152, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box8 = GUICtrlCreateCheckbox("Box 8", 141, 152, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box9 = GUICtrlCreateCheckbox("Box 9", 199, 152, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box10 = GUICtrlCreateCheckbox("Box 10", 257, 152, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box11 = GUICtrlCreateCheckbox("Box 11", 24, 210, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box12 = GUICtrlCreateCheckbox("Box 12", 83, 210, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box13 = GUICtrlCreateCheckbox("Box 13", 141, 210, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box14 = GUICtrlCreateCheckbox("Box 14", 199, 210, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box15 = GUICtrlCreateCheckbox("Box 15", 257, 210, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box16 = GUICtrlCreateCheckbox("Box 16", 24, 268, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box17 = GUICtrlCreateCheckbox("Box 17", 83, 268, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box18 = GUICtrlCreateCheckbox("Box 18", 141, 268, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box19 = GUICtrlCreateCheckbox("Box 19", 199, 268, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box20 = GUICtrlCreateCheckbox("Box 20", 257, 268, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box21 = GUICtrlCreateCheckbox("Box 21", 24, 326, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box22 = GUICtrlCreateCheckbox("Box 22", 83, 326, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box23 = GUICtrlCreateCheckbox("Box 23", 141, 326, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box24 = GUICtrlCreateCheckbox("Box 24", 199, 326, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$box25 = GUICtrlCreateCheckbox("Box 25", 257, 326, 57, 57, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
#ce

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

 

invalid box.jpg

valid box.jpg

Link to comment
Share on other sites

  • Solution

Is that what you need?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ###
$Form1 = GUICreate("Form1", 341, 443, -1, -1)
$Group1 = GUICtrlCreateGroup("", 8, 40, 323, 361, -1, $WS_EX_TRANSPARENT)
$Tab1 = GUICtrlCreateTab(16, 64, 308, 329)
$TabSheet1 = GUICtrlCreateTabItem("Tab1")

Global $boxArray[5][5]

For $line = 0 To 4
    For $i = 0 To 4
        $boxArray[$line][$i] = GUICtrlCreateCheckbox('Box ' & ($line + $line*4 + $i + 1), 25 + $i*60, 95+$line*60, 50, 50, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
    Next
Next

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Or you can do it with a 1 dimensional array and a single loop like this:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ###
$Form1 = GUICreate("Form1", 341, 443, -1, -1)
$Group1 = GUICtrlCreateGroup("", 8, 40, 323, 361, -1, $WS_EX_TRANSPARENT)
$Tab1 = GUICtrlCreateTab(16, 64, 308, 329)
$TabSheet1 = GUICtrlCreateTabItem("Tab1")

Global $boxArray[25]

For $index = 0 To 24
    $boxArray[$index] = GUICtrlCreateCheckbox('Box ' & $index + 1, 25 + Mod($index, 5) * 60, 95 + Int($index/5) * 60, 50, 50, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
Next

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Edited by Andreik

When the words fail... music speaks.

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