|
-
Mar 9th, 2010, 10:20 AM
#1
Thread Starter
Junior Member
[RESOLVED] how to get the sum of all values of rows in a certain column?

_______________
lcolumn 1l
l 3 l
l 4 l
l 5 l
(textbox)
sum
how to get the sum?????
-
Mar 9th, 2010, 10:25 AM
#2
Re: how to get the sum of all values of rows in a certain column?
Welcome to the forums... 
What are you referring with the word 'column' ? An array? ListView column ? FlexGrid column ?
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Mar 9th, 2010, 10:26 AM
#3
Thread Starter
Junior Member
Re: how to get the sum of all values of rows in a certain column?
-
Mar 9th, 2010, 10:57 AM
#4
Re: how to get the sum of all values of rows in a certain column?
Something like this might work:
VB Code:
Dim index As Integer Dim mySum As Double Dim columnToSum as integer mySum = 0 columnToSum = 1 For index = 1 To (MSFlexGrid1.Rows - 1) mySum = mySum + Val(MSFlexGrid1.TextMatrix(index, columnToSum)) Next index MsgBox mySum
Make the index variable a long if you have more than 32767 rows in your grid.
I started at index = 1 as I assumed you have a header row, if you don't and just have data without a header, change "index = 1 to" to "index = 0 to".
I'm not sure if there is a way to run a sub-sql-query directly on the underlying RecordSet but if not then the above hopefully works for you.
You might want to add some validation in case of NULL values.
Last edited by Optional; Mar 9th, 2010 at 11:03 AM.
Kind Regards,
Optional
If you feel this post has helped in answering your question please return the favour and Rate this post.
If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.
VB6 - (DataGrid) Get the Row selected with the right mouse button
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|