Jump to content
Sign in to follow this  
svenjatzu

Checkbox problem creating list - need help

Recommended Posts

Hi

im trying to create a simple tool where i can add 10-20 fixed listing items so that i can just mark the items i need and then save the marked list to a file, in best case to pdf.

 

on my search how to make it i found a script thats similar. im editing it to what i need but theres one point where i cant figure out how to make it right.

the tool just gives me a list of 10 fileds called checkbox 1-10 and i cant change it cuz theres a loop inside that creates the sample names.

 

someone experienced please can check out what the problem is in the script?

 

theres some more thing i cant figure out how to change it. on the left side theres an dropdown menu, i think i wont need that for my tool, just the plain checkbox area with the options i wanna add, eg

[] tomatoe

[] cheese

[] paprika

[] mushrooms

[] peanuts

[] cola

[] honey

maybe its more easy to just create the whole script new?

after choosing the items it should create the file with the chosen items and thats it.

thats the script so far

#NoTrayIcon
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $hGUI_MainWindow, $hGUI_CTRL_LBL_Steps, $hGUI_CTRL_GRP_Unlabeled1, $hGUI_CTRL_INP_Search, $hGUI_CTRL_BTN_Submit
Global $hGUI_CTRL_LBL_IssueList1, $hGUI_CTRL_CMB_IssueList1, $hGUI_CTRL_LBL_IssueList2, $hGUI_CTRL_CMB_IssueList2
Global $hGUI_CTRL_LBL_IssueList3, $hGUI_CTRL_CMB_IssueList3, $hGUI_CTRL_LBL_IssueList4, $hGUI_CTRL_CMB_IssueList4
Global $hGUI_CTRL_GRP_Unlabeled2, $hGUI_CTRL_LBL_IssueWnd1, $hGUI_CTRL_BTN_Copy2Clip, $aGUI_CTRL_CHK_GroupedBoxes[10]
Global $iGUI_Message, $iLoop, $sChkValues, $iUBound1D = UBound($aGUI_CTRL_CHK_GroupedBoxes, 1) - 1
WinGUI_Construct()
While 1
    $iGUI_Message = GUIGetMsg()
    Switch $iGUI_Message
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hGUI_CTRL_CMB_IssueList1
            If GUICtrlRead($hGUI_CTRL_CMB_IssueList1) = 'liste' Then
                GUICtrlSetState($hGUI_CTRL_LBL_IssueWnd1, $GUI_SHOW)
                GUICtrlSetState($hGUI_CTRL_BTN_Copy2Clip, $GUI_SHOW)
                For $iLoop = 0 To $iUBound1D Step 1
                    GUICtrlSetState($aGUI_CTRL_CHK_GroupedBoxes[$iLoop], $GUI_SHOW)
                Next
            Else
                GUICtrlSetState($hGUI_CTRL_LBL_IssueWnd1, $GUI_HIDE)
                GUICtrlSetState($hGUI_CTRL_BTN_Copy2Clip, $GUI_HIDE)
                For $iLoop = 0 To $iUBound1D Step 1
                    GUICtrlSetState($aGUI_CTRL_CHK_GroupedBoxes[$iLoop], $GUI_HIDE)
                Next
            EndIf
        Case $hGUI_CTRL_BTN_Copy2Clip
            $sChkValues = ''
            For $iLoop = 0 To $iUBound1D Step 1
                If GUICtrlRead($aGUI_CTRL_CHK_GroupedBoxes[$iLoop]) = $GUI_CHECKED Then $sChkValues &= "step " & $iLoop + 1 & @CRLF
                Next
            MsgBox(0, '', $sChkValues)            ;hier sendet der output
        FileWrite("neu.txt",$sChkValues&@CRLF)    ;speichern als txt
            WinClose("Steps","")                  ;fenster schliessen
    EndSwitch
WEnd
Func WinGUI_Construct()
    $hGUI_MainWindow = GUICreate('Steps', 1403, 800, -1, 3)
    $hGUI_CTRL_LBL_Steps = GUICtrlCreateLabel('Steps', 0, 40, 1894, 73)
    GUICtrlSetFont($hGUI_CTRL_LBL_Steps, 14, 400, 0, 'MS Sans Serif')
    GUICtrlSetBkColor($hGUI_CTRL_LBL_Steps, 0xA6CAF0)
    $hGUI_CTRL_GRP_Unlabeled1 = GUICtrlCreateGroup('', 8, 112, 433, 657)
    GUICtrlSetColor($hGUI_CTRL_GRP_Unlabeled1, 0x000000)
;~     $hGUI_CTRL_INP_Search = GUICtrlCreateInput('Search', 24, 136, 201, 24)
;~     $hGUI_CTRL_LBL_IssueList1 = GUICtrlCreateLabel('Button1', 28, 184, 42, 20)
    $hGUI_CTRL_CMB_IssueList1 = GUICtrlCreateCombo('', 96, 184, 329, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
    GUICtrlSetData($hGUI_CTRL_CMB_IssueList1, 'liste')
;~     $hGUI_CTRL_LBL_IssueList2 = GUICtrlCreateLabel('Button2', 24, 240, 69, 20)
;~     $hGUI_CTRL_CMB_IssueList2 = GUICtrlCreateCombo('', 96, 240, 329, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
;~     GUICtrlSetData($hGUI_CTRL_CMB_IssueList2, '|First issue|Second issue')
;~     $hGUI_CTRL_LBL_IssueList3 = GUICtrlCreateLabel('Button3', 24, 296, 66, 20)
;~     $hGUI_CTRL_CMB_IssueList3 = GUICtrlCreateCombo('', 96, 296, 329, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
;~     GUICtrlSetData($hGUI_CTRL_CMB_IssueList3, '|First issue|Second issue')
;~     $hGUI_CTRL_LBL_IssueList4 = GUICtrlCreateLabel('Button4', 24, 352, 69, 20)
;~     $hGUI_CTRL_CMB_IssueList4 = GUICtrlCreateCombo('', 96, 352, 329, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
;~     GUICtrlSetData($hGUI_CTRL_CMB_IssueList4, '|First issue|Second issue')
;~     $hGUI_CTRL_BTN_Submit = GUICtrlCreateButton('Submit', 272, 136, 155, 25, $BS_DEFPUSHBUTTON)
;~     GUICtrlCreateGroup('', -99, -99, 1, 1)
    $hGUI_CTRL_GRP_Unlabeled2 = GUICtrlCreateGroup('', 464, 112, 1425, 625)
    $hGUI_CTRL_LBL_IssueWnd1 = GUICtrlCreateLabel("liste", 480, 136, 1393, 29)
    GUICtrlSetFont($hGUI_CTRL_LBL_IssueWnd1, 12, 400, 0, "MS Sans Serif")
    GUICtrlSetState($hGUI_CTRL_LBL_IssueWnd1, $GUI_HIDE)
    $hGUI_CTRL_BTN_Copy2Clip = GUICtrlCreateButton("Copy to Clipboard", 504, 640, 139, 25)
    GUICtrlSetState($hGUI_CTRL_BTN_Copy2Clip, $GUI_HIDE)
    GUICtrlSetBkColor($hGUI_CTRL_BTN_Copy2Clip, 0xC0DCC0)
    For $iLoop = 0 To $iUBound1D Step 1                      ;here it creates the loop i think : /
        $aGUI_CTRL_CHK_GroupedBoxes[$iLoop] = GUICtrlCreateCheckbox("Checkbox" & $iLoop + 1, 504, 184 + (40 * $iLoop), 97, 17)
        GUICtrlSetState($aGUI_CTRL_CHK_GroupedBoxes[$iLoop], $GUI_HIDE)
    Next
    GUICtrlCreateGroup('', -99, -99, 1, 1)
    GUISetState(@SW_SHOW)
EndFunc   ;==>WinGUI_Construct

 

Share this post


Link to post
Share on other sites
4 hours ago, svenjatzu said:

maybe its more easy to just create the whole script new?

Yes, for sure.

That's because you could use a single control called ListView, in which you can create as many items as you want, with subitems either (a sort of table with rows and columns), where you can have checkboxes too.

It'd be much simpler to do that instead of trying to modify that script.

Take a look at GUICtrlCreateListView* and _GUICtrlListView_* functions in the Help file :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
4 hours ago, FrancescoDiMuro said:

Yes, for sure.

That's because you could use a single control called ListView, in which you can create as many items as you want, with subitems either (a sort of table with rows and columns), where you can have checkboxes too.

It'd be much simpler to do that instead of trying to modify that script.

Take a look at GUICtrlCreateListView* and _GUICtrlListView_* functions in the Help file :)

i cant make it im cind of to stupid to understand how to do it

Share this post


Link to post
Share on other sites

In your post above you just need to create an array with all of your different items and then you loop through it to add the checkboxes.  As FrancisDiMuro suggested, listview is another way to tackle it, see basic example below:

Create a file named Listitems.ini with the following items, add/remove as many items, just remember the format "Key = ", we don't add a value because we don't need any.

[List Items]
tomato = 
cheese =
paprika = 
mushrooms = 
peanuts = 
cola = 
honey =

Then save and run the following script in the same folder as the ini file.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $sSelected = "", $sListitemsIni = @ScriptDir & "\Listitems.ini"
    Local $aListitems = IniReadSection($sListitemsIni, "List Items")
        If @error Then Exit MsgBox(4096, "Error", "Error reading Listitems.ini" & @CRLF & "Exiting...")
        _ArrayDelete($aListitems, 0)
    Local $iListviewHeight = UBound($aListitems) * 25 < 530 ? UBound($aListitems) * 25 : 530 ;~ Set Listview Height, max size 530
    Local $iGuiHeight = (10 + $iListviewHeight + 10 + 30 + 10) < 600 ? (10 + $iListviewHeight + 10 + 30 + 10) : 600
    Local $hWndGui = GUICreate("Select Items ", 400, $iGuiHeight)
    Local $idListview = GUICtrlCreateListView("List Items|", 10, 10, 380, $iListviewHeight, -1, BitOR($WS_EX_CLIENTEDGE , $LVS_EX_CHECKBOXES))
    Local $idSaveButton = GUICtrlCreateButton("Save", 245, 10 + $iListviewHeight + 10, 70, 30)
    Local $idCancel = GUICtrlCreateButton("Cancel", 320, 10 + $iListviewHeight + 10, 70, 30)
    _GUICtrlListView_AddArray($idListview, $aListitems)
    _GUICtrlListView_SetColumnWidth($idListview, 0, 375)
    _GUICtrlListView_SetColumnWidth($idListview, 1, 0)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idCancel
                ExitLoop
            Case $idSaveButton
                $sSelected = ""
                For $i = 0 To _GUICtrlListView_GetItemCount($idListview)
                    If _GUICtrlListView_GetItemChecked($idListview, $i) Then $sSelected &= _GUICtrlListView_GetItemText($idListview, $i, 0) & @CRLF
                Next
                If $sSelected <> "" Then
                    ClipPut($sSelected)
                    MsgBox(4096, "Selected Items", "Added to Clipboard" & @CRLF & $sSelected)
                Else
                    MsgBox(4096, "Selected Items", "No items were selected")
                EndIf
        EndSwitch
    WEnd
EndFunc

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...