473,951 Members | 34,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Solution to total a specific column in a list box

convexcube
47 New Member
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 14224
missinglinq
3,532 Recognized Expert Specialist
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
convexcube
47 New Member
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 Recognized Expert Specialist
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 inappropriatene ss 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
convexcube
47 New Member
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" , "unacceptab le" 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
Al Cohen
1 New Member
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,585 Recognized Expert Moderator MVP
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
1560
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 problem is that I get the following to-much detailed message: System.FormatException: Input string was not in a correct format. at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int32.Parse(String s,...
1
2560
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 one. Also, it seems that even when i set listview to have 3 colums, there's a fourth one with no header. How can I remove it and have only 3
0
1322
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' whichever would be easier. The rest of what I need to do once I have the data I am ok with but the connecting to the spreadsheet and extracting a column into an array or dataset or whatever would work best I have no clue. I would appreciate some...
7
26410
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 found quite interesting the linecache module but unfortunately that is (to my knowledge) only working on lines, not columns. Any suggestion?
1
1342
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 showing the new date is displayed. How can I accomplish that ?
1
4901
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 in the list box). I need to it also select multiple sets of records (Multi-Select = Extended). I modified my code based on code I found on some Internet site which gave an example using three fields in a three field table. It loops through the...
2
6050
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 based on the specific column. For example: FIRSTNAME LASTNAME AGE John Doe 24 Bill Jones 43 Judy Smith 21 Sally Johnson 38 I thought I could have each button change the RowSource order of the List Box using simple VBA code; something like:
2
8327
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 = "DESIRED COLUMN"; (here I got the values I want, but including empty rows, and with repetitions).
0
10173
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11377
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10703
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9907
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8270
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3563
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.