Connecting Tech Pros Worldwide Forums | Help | Site Map

How to sum a 'column' in a listbox holding tab-delimited text

Newbie
 
Join Date: May 2007
Posts: 2
#1: May 21 '07
I have a question about list box too if i may.. I have a listbox with entries in it like the following; 5 0 3 2 9 6. The spaces are tabs on the same line. That is just one line, I will have 31 lines meaning 31 days wich represent the first entry, the 5 in this case, the rest of the numbers are dif items sold for that day. How can i sum up the total of the colums on a button click event? Any help will be appreciated..

Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#2: May 22 '07

re: How to sum a 'column' in a listbox holding tab-delimited text


Quote:

Originally Posted by ciscohomie

I have a question about list box too if i may.. I have a listbox with entries in it like the following; 5 0 3 2 9 6. The spaces are tabs on the same line. That is just one line, I will have 31 lines meaning 31 days wich represent the first entry, the 5 in this case, the rest of the numbers are dif items sold for that day. How can i sum up the total of the colums on a button click event? Any help will be appreciated..

As far as I know, all the listbox has is an array of strings (rows), not columns. So to sum a column you would need to loop through the entries, split them (use the Split() function) and add the resulting details. For example, to pick out the third "column" (skipping the count at the start) from the fifth "row" I believe the expression would be somethiing like Split(lstNum(4), vbTab)(3).

That is, take the value of lstNum(4), then use Split() to pull it apart at the tabs, creating an array. Use element 3 from the array. VB just says it in a more compact form. :)

Note, I'm pretty sure that they both start at zero but I've allowed for the "count column".
Newbie
 
Join Date: May 2007
Posts: 2
#3: May 22 '07

re: How to sum a 'column' in a listbox holding tab-delimited text


Quote:

Originally Posted by Killer42

As far as I know, all the listbox has is an array of strings (rows), not columns. So to sum a column you would need to loop through the entries, split them (use the Split() function) and add the resulting details. For example, to pick out the third "column" (skipping the count at the start) from the fifth "row" I believe the expression would be somethiing like Split(lstNum(4), vbTab)(3).

That is, take the value of lstNum(4), then use Split() to pull it apart at the tabs, creating an array. Use element 3 from the array. VB just says it in a more compact form. :)

Note, I'm pretty sure that they both start at zero but I've allowed for the "count column".


Yes an array is writing to listbox and txt file from txtboxes. I will try it out and see what i come up with. Will let you know. Thanks.
Reply