ca143508 Posted February 25, 2007 Share Posted February 25, 2007 Guys, I am not sure if it is possible but I would like to get the combined value of a column. The values are for example 2007/12/25|$50.00|Xmas Gift 2007/12/24|$35.50|Lunch So I'd like to get the total of column 2 ($85.50). Any tips??? Cheers, Mike. Link to comment Share on other sites More sharing options...
xcal Posted February 25, 2007 Share Posted February 25, 2007 Ok, I'm bored, so have a look at this: expandcollapse popup#include <GUIConstants.au3> #include <GUIListView.au3> GUICreate('Add Columns', 300, 200) $lv = GUICtrlCreateListView('Date|Amount|Item', 10, 10, 280, 144) GUICtrlCreateListViewItem('2007/12/25|$50.00|Xmas Gift', $lv) GUICtrlCreateListViewItem('2007/12/24|$35.50|Lunch', $lv) GUICtrlCreateListViewItem('2007/12/23|$60.00|Hookers', $lv) GUICtrlCreateListViewItem('2007/12/23|$35.00|Hooker''s Lunch', $lv) _GUICtrlListViewSetColumnWidth($lv, 0, 70) $btn = GUICtrlCreateButton('Get Total!', 10, 164, 60, 26) $lbl = GUICtrlCreateLabel('Total is: $00.00', 80, 164, -1, -1, $SS_CENTERIMAGE + $SS_CENTER) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $btn GUICtrlSetData($lbl, 'Total is: $' & _addit()) EndSwitch WEnd Func _addit() Local $num_total = 0 For $i = 0 To _GUICtrlListViewGetItemCount($lv) $num = StringTrimLeft(_GUICtrlListViewGetItemText($lv, $i, 1), 1) If $num = '' Then ContinueLoop $num_total += $num Next Return StringFormat('%.2f', $num_total) EndFunc How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
ca143508 Posted February 25, 2007 Author Share Posted February 25, 2007 Ok, I'm bored, so have a look at this: expandcollapse popup#include <GUIConstants.au3> #include <GUIListView.au3> GUICreate('Add Columns', 300, 200) $lv = GUICtrlCreateListView('Date|Amount|Item', 10, 10, 280, 144) GUICtrlCreateListViewItem('2007/12/25|$50.00|Xmas Gift', $lv) GUICtrlCreateListViewItem('2007/12/24|$35.50|Lunch', $lv) GUICtrlCreateListViewItem('2007/12/23|$60.00|Hookers', $lv) GUICtrlCreateListViewItem('2007/12/23|$35.00|Hooker''s Lunch', $lv) _GUICtrlListViewSetColumnWidth($lv, 0, 70) $btn = GUICtrlCreateButton('Get Total!', 10, 164, 60, 26) $lbl = GUICtrlCreateLabel('Total is: $00.00', 80, 164, -1, -1, $SS_CENTERIMAGE + $SS_CENTER) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $btn GUICtrlSetData($lbl, 'Total is: $' & _addit()) EndSwitch WEnd Func _addit() Local $num_total = 0 For $i = 0 To _GUICtrlListViewGetItemCount($lv) $num = StringTrimLeft(_GUICtrlListViewGetItemText($lv, $i, 1), 1) If $num = '' Then ContinueLoop $num_total += $num Next Return StringFormat('%.2f', $num_total) EndFunc XCAL - you the man! Link to comment Share on other sites More sharing options...
frodo Posted March 3, 2007 Share Posted March 3, 2007 (edited) Came cross this thread while trying to find an eays way to add multiple items together. The example above gave me a great start, so im posting the slightly modified code for adding multiple selected items below. CODE #include <GUIConstants.au3> #include <GUIListView.au3> GUICreate('Add Columns', 300, 200) $lv = GUICtrlCreateListView('Date|Amount|Item', 10, 10, 280, 144, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER)) GUICtrlCreateListViewItem('2007/12/25|$50.00|Xmas Gift', $lv) GUICtrlCreateListViewItem('2007/12/24|$35.50|Lunch', $lv) GUICtrlCreateListViewItem('2007/12/23|$60.00|Hookers', $lv) GUICtrlCreateListViewItem('2007/12/23|$35.00|Hooker''s Lunch', $lv) _GUICtrlListViewSetColumnWidth($lv, 0, 70) $btn = GUICtrlCreateButton('Get Total!', 10, 164, 60, 26) $lbl = GUICtrlCreateLabel('Total is: $00.00', 80, 164, -1, -1, $SS_CENTERIMAGE + $SS_CENTER) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $btn GUICtrlSetData($lbl, 'Total is: $' & _addit()) EndSwitch WEnd Func _addit() Dim $total Local $sa = _GUICtrlListViewGetSelectedIndices($lv,1) For $i = 1 To UBound($sa) - 1 $num = StringTrimLeft(_GUICtrlListViewGetItemText($lv, $sa[$i], 1), 1) $total = $total + $num Next Return StringFormat('%.2f', $total) EndFunc Edited March 3, 2007 by frodo Link to comment Share on other sites More sharing options...
xcal Posted March 3, 2007 Share Posted March 3, 2007 Change For $i = 1 To $sa[0] to For $i = 1 To UBound($sa) - 1. Otherwise you'll get an error if nothing is selected. How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
frodo Posted March 3, 2007 Share Posted March 3, 2007 Change For $i = 1 To $sa[0] to For $i = 1 To UBound($sa) - 1. Otherwise you'll get an error if nothing is selected. Ooops, good point, i was in a rush last night with my own code and solved it there,. Changed in original post! Thanks for the reminder, err kick in the pants 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