Results 1 to 4 of 4

Thread: [RESOLVED] how to get the sum of all values of rows in a certain column?

  1. #1

    Thread Starter
    Junior Member macmatira's Avatar
    Join Date
    Mar 2010
    Posts
    21

    Resolved [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?????

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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,...

  3. #3

    Thread Starter
    Junior Member macmatira's Avatar
    Join Date
    Mar 2010
    Posts
    21

    Re: how to get the sum of all values of rows in a certain column?

    flexgrid

  4. #4
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: how to get the sum of all values of rows in a certain column?

    Something like this might work:
    VB Code:
    1. Dim index As Integer
    2. Dim mySum As Double
    3. Dim columnToSum as integer
    4.  
    5. mySum = 0
    6. columnToSum = 1
    7.  
    8. For index = 1 To (MSFlexGrid1.Rows - 1)
    9.     mySum = mySum + Val(MSFlexGrid1.TextMatrix(index, columnToSum))
    10. Next index
    11.  
    12. 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
  •  



Click Here to Expand Forum to Full Width