lastmember Posted October 23, 2012 Share Posted October 23, 2012 (edited) hello There are beginner and want to know how can amount to several numbers that are in a listbox example: 2 5 3 How do I sum (10) in a label ? thanks in advance Edited October 23, 2012 by lastmember Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 23, 2012 Moderators Share Posted October 23, 2012 lastmember, Welcome to the AutoIt forum. Here is one way to do it: #include <GUIConstantsEx.au3> #include <GuiListBox.au3> $hGUI = GUICreate("Test", 500, 500) $cList = GUICtrlCreateList("", 10, 10, 200, 200) For $i = 1 To 5 GUICtrlSetData($cList, Random(1, 100, 1)) Next $cButton_Add = GUICtrlCreateButton("Add", 250, 10, 80, 30) $cLabel = GUICtrlCreateLabel("", 10, 250, 200, 20) $cButton_Sum = GUICtrlCreateButton("Sum", 10, 300, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton_Add GUICtrlSetData($cList, Random(1, 100, 1)) Case $cButton_Sum $iCount = _GUICtrlListBox_GetCount($cList) $iSum = 0 For $i = 0 To $iCount - 1 $iSum += Number(_GUICtrlListBox_GetText($cList, $i)) Next GUICtrlSetData($cLabel, $iSum) EndSwitch WEnd All clear? Please ask if not 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
lastmember Posted October 23, 2012 Author Share Posted October 23, 2012 yeess!!works wellthank you very much ! Link to comment Share on other sites More sharing options...
lastmember Posted October 23, 2012 Author Share Posted October 23, 2012 Now I have another questionI have the following:#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("test", 288, 307, 202, 164) $List1 = GUICtrlCreateList("", 5, 4, 273, 227) $Button1 = GUICtrlCreateButton("test", 7, 236, 268, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 read() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func read() $iniread = IniReadSection(@ScriptDir & "test.ini", "section1") If @error Then MsgBox(4096, "", "no have ini file!") Else For $i = 1 To $iniread[0][0] GUICtrlSetData($list1,$iniread[$i][1]) Next endif EndFuncin test.ini section1, we next:key1=testkey2=testkey3=test1key4=test2but I do not upload $ List1 thantesttest1test2where am I wrong to not load all 4 keysnot repeat those loading than oncethanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 23, 2012 Moderators Share Posted October 23, 2012 lastmember,Please start a new topic if you have a new question - we do not mind at all. GUICtrlSetData works strangely for List controls. If you try to add something that is already present, it does not do so - which is why you only get the one "test". You need to add all the items at the same time like this: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("test", 288, 307, 202, 164) $List1 = GUICtrlCreateList("", 5, 4, 273, 227) $Button1 = GUICtrlCreateButton("test", 7, 236, 268, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 read() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func read() $iniread = IniReadSection(@ScriptDir & "test.ini", "section1") If @error Then MsgBox(4096, "", "no have ini file!") Else $sIniFill = "" For $i = 1 To $iniread[0][0] $sIniFill &= "|" & $iniread[$i][1] Next GUICtrlSetData($List1, $sIniFill) EndIf EndFunc ;==>readNow you get any multiple entries added to the list. All clear? 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
lastmember Posted October 24, 2012 Author Share Posted October 24, 2012 yes it works ... I need to document to understand what is written: $sIniFill &= "|" Thanks again for the prompt and you had patience with me! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 24, 2012 Moderators Share Posted October 24, 2012 lastmember,As we need to fill the list control in a single command to make sure we get possible duplicate entries, we need to tell AutoIt when each entry begins and ends in the string we pass to the list - we do this using the GUIDataSeparatorChar. By default this is set to "|", but you can change it using Opt.So $sIniFill &= "|" & $iniread[$i][1] just adds the separator between each entry - and the fact that there is a leading "|" means that any previous content is destroyed, as explained in the Help file entry for GUICtrlSetData.All clear now? 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
lastmember Posted October 24, 2012 Author Share Posted October 24, 2012 yes it is explained in the help, thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now