Jump to content

Create x numbers of checkboxes with dynimic names


Kiesp
 Share

Recommended Posts

I would like to create an unknown number of checkboxes in my gui.

The number of checkboxes are decided by a file. It simply counts the number of lines. This is not the problem.

The problem is that i would like to be able to read the state of these checkboxes. But to do that i need a controlname (correct me if im wrong)

How can i create checkboxes with controlnames dynamicly. The problem is that there can be between 3 and 100 lines in this file.

Thanks in advance ;)

Kiesp

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Link to comment
Share on other sites

  • Moderators

Kiesp,

Store the checkbox ControlIds in an array. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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

 

Link to comment
Share on other sites

Can you give an example ? ;)

I think that i have "starred myself blind" on the code.

my code is still very messy.. and i dont have anything major in it. can post of needed though :)

Edited by Kiesp

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Link to comment
Share on other sites

#include <WindowsConstants.au3>
#Include <File.au3>
#Include <Array.au3>
#include <GUIConstantsEx.au3>
Opt("TrayIconHide",1)

Global $name, $i, $names,$navne, $ophei
$o = 0
$q = 0
$l = 5
$t = 5

if Not FileExists("Servicedesk personer.txt") Then
    fejl()
EndIf
if _FileReadToArray("Servicedesk personer.txt",$navne) = 0 Then fejl()
_ArrayAdd($navne,"")
_ArrayAdd($navne,"")

Global $variables[$navne[0]]

for $q = 0 To $navne[0] Step 2
    $ophei += 22
Next

$maingui = GUICreate("Servicedesk.",150,70,-1,-1,-1,BitOR($WS_EX_TOOLWINDOW,$WS_EX_APPWINDOW))
$roll1 = GUICtrlCreateButton("     Frokost     ",30,10)
$roll2 = GUICtrlCreateButton("      Møde       ",30,40)
$opt = GUICtrlCreateButton(" Mere ",110,25)
GUISetState(@SW_SHOW,$maingui)

$optiongui = GUICreate("",165,$ophei,-1,-1,-1,$WS_EX_TOOLWINDOW,$maingui)
for $w = 1 To $navne[0]
    $qq = $navne[$w]
    guictrlcreatecheckbox($navne[$w],$l,$t)
    ;MsgBox(0,"",guictrlgetstate($qq))
    ;MsgBox(0,"",GUICtrlGetHandle("[CLASS:Button; INSTANCE:1]"))
    GUICtrlSetState($navne[$w],$GUI_CHECKED)
    if $l = 5 Then
        $l = 100
    Else
        $l = 5
        $t += 25
    EndIf
Next


while 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = -3 And $msg[1] = $maingui
            Exit
        case $msg[0] = $roll1
            GUICtrlDelete($roll1)
            GUICtrlDelete($roll2)
            GUICtrlDelete($opt)
            shuffle(2)
            GUISetState(@sw_hide,$optiongui)
        case $msg[0] = $roll2
    MsgBox(0,"",GUICtrlGetHandle("[CLASS:Button; INSTANCE:1]"))
            GUICtrlDelete($roll1)
            GUICtrlDelete($roll2)
            GUICtrlDelete($opt)
            shuffle(1)
            GUISetState(@sw_hide,$optiongui)
        Case $msg[0] = -3 And $msg[1] = $optiongui
            GUISetState(@sw_hide,$optiongui)
        Case $msg[0] = $opt
            GUISetState(@SW_SHOW,$optiongui)
    EndSelect
WEnd

Func fejl()
    if MsgBox(68,"Fejl","Du har ikke skrevet noget i ''Servicedesk personer.txt''" & @CRLF & "Vil du åbne filen ?") = 6 Then
        $SSDH = FileOpen("Servicedesk personer.txt",9)
        FileClose($SSDH)
        ShellExecuteWait(@ScriptDir & "\" & "Servicedesk personer.txt")
        if _FileReadToArray("Servicedesk personer.txt",$navne) = 0 then Exit
    Else
        Exit
    EndIf   
EndFunc

func shuffle($nrop)
    $totalnavne = $navne[0]
    for $i = 1 to $nrop
        $rand = Random(1,$totalnavne,1)
        if $navne[$rand] = "" Then
            $name = $navne[$rand + 1]
            ;if $navne[$rand] = "" Then $name = $navne[$rand - 2]
        Else
            $name = $navne[$rand]
        EndIf
        $navne[$rand] = ""
        $names = $names & $name & ","
    Next
    if $nrop = 2 Then
        $names = StringSplit($names,",")
        $names = $names[1] & " og " & $names[2]
        $section = "Frokost"
        $lbl = GUICtrlCreateLabel($names,10,5,140,30)
        GUICtrlSetFont($lbl,12,600)
        GUICtrlCreateLabel("Skal til frokost",35,40)
    Else
        $names = StringTrimRight($names,1)
        $section = "Møde"
        $lbl = GUICtrlCreateLabel($names,40,5,90,30)
        GUICtrlSetFont($lbl,12,600)
        GUICtrlCreateLabel("Skal blive på telefonen",15,40)
    EndIf
    IniWrite("Servicedesk.log",$section,@MDAY & "/" & @MON & "-" & @YEAR,$names)
EndFunc

Please dont criticize my messy code ;)

This is the part that i tried with so far

$qq = $navne[$w]
    guictrlcreatecheckbox($navne[$w],$l,$t)
    ;MsgBox(0,"",guictrlgetstate($qq))
    ;MsgBox(0,"",GUICtrlGetHandle("[CLASS:Button; INSTANCE:1]"))
    GUICtrlSetState($navne[$w],$GUI_CHECKED)

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Link to comment
Share on other sites

Hi, dynamic checkboxes based on the height of the window

#include <GUIConstantsEx.au3>

Global $hGui, $aWinPos, $aCheckBox, $iMsg, $sState

$hGui = GUICreate("")
$aWinPos = WinGetPos($hGui)
Dim $aCheckBox[Int($aWinPos[3] / 30)]
For $i = 0 To UBound($aCheckBox) - 1
    $aCheckBox[$i] = GUICtrlCreateCheckbox("CheckBox " & $i + 1, 5, 5 + ($i * 30), 100, 25)
Next
GUISetState(@SW_SHOW, $hGui)

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aCheckBox[0] To UBound($aCheckBox) - 1
            If BitAND(GUICtrlRead($iMsg), $GUI_CHECKED) Then
                $sState = "CHECKED"
            Else
                $sState = "UNCHECKED"
            EndIf
            MsgBox(64, "CheckBox Clicked", "Control ID: " & $iMsg & @LF & "CheckBox Text: " & GUICtrlRead($iMsg, 1) & @LF & "CheckBox State: " & $sState)
    EndSwitch
WEnd

Cheers

Edited by smashly
Link to comment
Share on other sites

Hi, dynamic checkboxes based on the height of the window

#include <GUIConstantsEx.au3>

Global $hGui, $aWinPos, $aCheckBox, $iMsg, $sState

$hGui = GUICreate("")
$aWinPos = WinGetPos($hGui)
Dim $aCheckBox[Int($aWinPos[3] / 30)]
For $i = 0 To UBound($aCheckBox) - 1
    $aCheckBox[$i] = GUICtrlCreateCheckbox("CheckBox " & $i + 1, 5, 5 + ($i * 30), 100, 25)
Next
GUISetState(@SW_SHOW, $hGui)

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aCheckBox[0] To UBound($aCheckBox) - 1
            If BitAND(GUICtrlRead($iMsg), $GUI_CHECKED) Then
                $sState = "CHECKED"
            Else
                $sState = "UNCHECKED"
            EndIf
            MsgBox(64, "CheckBox Clicked", "Control ID: " & $iMsg & @LF & "CheckBox Text: " & GUICtrlRead($iMsg, 1) & @LF & "CheckBox State: " & $sState)
    EndSwitch
WEnd

Cheers

Thats very nice ;) But it doesn't really solve my problem :)

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Link to comment
Share on other sites

  • Moderators

Kiesp,

But it doesn't really solve my problem

Yes it does. ;)

- It shows how to declare an array of a certain size. You just have to use the number of lines in your file, which you can get in a number of ways - you are using _FileReadToArray so you already have that information!

- It then shows how to create the correct number of checkboxes, storing their ControlIDs in the array.

- It finally shows you how to read those checkboxes and see if they have been checked or not.

Now go and try to incorporate those elements into your code. We are trying to get you to understand the code you write, so we are not going to write you a complete solution. Come back with any problems and we will point you in the right direction. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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

 

Link to comment
Share on other sites

Kiesp,

Yes it does. ;)

- It shows how to declare an array of a certain size. You just have to use the number of lines in your file, which you can get in a number of ways - you are using _FileReadToArray so you already have that information!

- It then shows how to create the correct number of checkboxes, storing their ControlIDs in the array.

- It finally shows you how to read those checkboxes and see if they have been checked or not.

Now go and try to incorporate those elements into your code. We are trying to get you to understand the code you write, so we are not going to write you a complete solution. Come back with any problems and we will point you in the right direction. :shocked:

M23

Took at break, listened to some music and talked to some friends. Looked at the code again and now i can see that it helps me :) Thanks for pointing it out :)

I shall return shortly and tell u if i got it working or not ;)

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Link to comment
Share on other sites

  • Moderators

Kiesp,

Took at break, listened to some music and talked to some friends

Always helps! Personally I would add a glass or two of wine to the equation! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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

 

Link to comment
Share on other sites

Kiesp,

Always helps! Personally I would add a glass or two of wine to the equation! :)

M23

Ya.. thats not a bad idea either ;) Except for one small problem.. Im on the job ^^

Anyways.. i got it working thanks to you guys ;) so thanks ALOT! u saved me hours and probably half of my hair ^^

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Link to comment
Share on other sites

  • Moderators

Kiesp,

Glad we could help. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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

 

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