473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Solution to total a specific column in a list box

convexcube
After searching the web for a solution to total a specific column in a list box and not finding it, I came up with this:

Expand|Select|Wrap|Line Numbers
  1. Dim varTotal As Currency
  2. Dim varRow As Integer
  3. For varRow = 1 To (lstListbox.ListCount - 1)
  4. varTotal = varTotal + lstListbox.Column(2, varRow)
  5. Next
  6. txtTotal = varTotal
This will provide a total in txtTotal for the third column (referenced as "2" because the first column is "0") in the list box as currency.
  • Change "lstListbox" to your list box name
  • Ensure you have an unbound text box called "txtTotal" on the form. (or call it something else, but be sure to change the code in line 5 to reference it)
  • To change to a different column, alter the "2" in line 4.
  • I have Column Heads set to "Yes" in my list box which requires a "-1" to be placed in row 3. Remove this if there are no Column Heads.
  • If totaling a different data type, change "Currency" in line 1 to your data type.

Hope this can provide some help to someone.

Regards,
Ken.
Dec 19 '07 #1
6 14110
missinglinq
3,532 Expert 2GB
The reason searching the web for a solution to "total a specific column in a list box" came up empty is very simple: Listboxes are meant to be used to allow users to select data for inclusion in a record, not for simply displaying data! If used properly, there is no valid reason to sum up a Listbox column's data!

You should have been using a subform to display your data, in which case the summing of a column would have been very simple.

Linq ;0)>
Jan 5 '08 #2
The reason searching the web for a solution to "total a specific column in a list box" came up empty is very simple: Listboxes are meant to be used to allow users to select data for inclusion in a record, not for simply displaying data! If used properly, there is no valid reason to sum up a Listbox column's data!

You should have been using a subform to display your data, in which case the summing of a column would have been very simple.

Linq ;0)>
I really don't think there's any need to be so condescending. I never said I wasn't using the list box to select data. It can still be useful for the user to see a total. At any rate all I was trying to do was provide the solution I came up with so anyone who might want to do it, but is not sure how, can. If people are denigrated for being creative then innovation will cease for sure.

Regards,
Ken.
Jan 5 '08 #3
missinglinq
3,532 Expert 2GB
I wasn't being condescending, Ken, merely pointing out to you, and to others who might read the thread, that Listboxes are not intended to be used as primary data display objects!

In responding to questions posted here, we have two objectives:



  1. To aid the original poster in solving his/her particular problem
  2. To provide information on the subject that may be helpful to others who come upon the thread
Because of the second objective listed above, it would be remiss of me not to comment on the inappropriateness of using Listboxes in this manner. Others coming along could get the idea that this was an acceptable usage, and that's simply not true.

Pointing out mistakes is never done to denigrate the poster, it's simply done so that others may avoid making the same ones! Innovation and creativity is what programming is all about, and we would never intentionally do anything here to discourage it!

Lastly, as a point of order, the technical forums here at TSDN are for the posting of questions and/or problems, and as such are not the proper venues for posting instructional threads. We are always happy to receive and evaluate such threads, but they should be posted in the HowTo section of the site.

Despite the wrongness of using Listboxes for the primary display of data, it's truly a pleasure to come across someone like yourself, who actually attempts to solve their own problems, instead of simply posting them and saying "Someone please do my work for me!"

I look forward, Ken, to seeing your future contributions here at TheScripts.

Linq ;0)>
Jan 6 '08 #4
Hello MissingLinq,

First of all, thanks for pointing out that this should have been posted in the how-to section. Although I now know this is the place the original post should have gone, at the time I didn't.

Secondly, I realise that it wasn't your intention to be condescending and denigrate this solution but I feel that the words you chose completely negated what I had to say. Although you describe using listboxes in this way is "not valid", "inappropriate", "unacceptable" and "wrong", the solution I came up with works and is valid. I agree that you should point out better solutions, but its definitely beneficial to recognise what people have achieved - especially if they are just starting out.

Lastly, I think this website is wonderful and has been an invaluable source of information. It is so beneficial to have such experts willing to share their knowledge and help newbies become more all in an open and free environment.


Kind Regards,
Ken.
Jan 10 '08 #5
Although this is about 3 1/2 years later, I needed to thank you for this solution to a problem I was having in 2011.

Keep on being creative...:)

Al
Mar 22 '11 #6
NeoPa
32,556 Expert Mod 16PB
I presume you read the rest of the thread Al, so I won't repeat the warning that Linq has already expressed. I assume you have already considered and disregarded this advice (which is entirely your right of course). We can only offer the benefits of our experience. We cannot force the horse to drink, as it were.

That said, I know thread resurrection is often frowned upon, but I appreciate the impulse that prompted you to thank ConvexCube for what is, after all, an innovative solution.
Mar 23 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Leeor Chernov | last post by:
Hi , I am using the method: DSSap.ReadXml( XmlPath,XmlReadMode.InferSchema ); And as I expected I get an error when the xml does not matching my DataSet that contains already a schema , The...
1
by: Eran.Yasso | last post by:
Hello all, This is my first time using listview. I was looking in google for a way to write to a specific column. I have 3 columns in my list view. I want to be able to write to a specific...
0
by: Problematic coder | last post by:
Hi, I have just been asked to create an app that will import a specific column from an excel spreadsheet, something like sheet1 columnD or a column with the first row with a value of 'ID'...
7
by: cesco | last post by:
Hi, I have a file containing four columns of data separated by tabs (\t) and I'd like to read a specific column from it (say the third). Is there any simple way to do this in Python? I've...
1
by: =?Utf-8?B?UGF1bCBT?= | last post by:
Hi I want to create a list as shown here http://www.zartorv.com/default.asp?id=45 It's a 2-column list with item's sorted on a date value. When the data value for the items break a header...
1
by: KrazyKasper | last post by:
Access 2003 – Multi-Column List Box – Select Multiple Items I have a multi-column (3 columns) list box that works well to select one set of records or all sets of records (based on the first field...
2
by: KrazyKasper | last post by:
I have a Multi-Column List Box named List10 that is populated via a query (qry_OptimizeIt3). I’m looking to create three Buttons, one above each column that will re-sort the list in ascending order...
2
by: anatanat | last post by:
hello :) I want to bind a combobox to a specific column in a DataTable. I want the combobox items to display distinct values. I tried: combo.datasource = dataTable; combo.DisplayMember =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.