Results 1 to 9 of 9

Thread: list1 how to sum the 5 column

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2016
    Posts
    220

    list1 how to sum the 5 column

    Hi, I'm ontro

    I can't sum the 5 column of list1


    I have the code in excel that does it well
    How would the code be in vb 6.0, thanks


    the code in excel is the following


    Code:
    Dim I As Integer
    Dim Sum As Double
    
    Sum = 0
        For I = 0 To ListBox1.ListCount - 1
        
            Sum = Sum + ListBox1.List(I, 4)'Column 5
    
        Next I
                TextBox2.Text = Sum

    how would the code be in vb 6.0

    Thank you

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,904

    Re: list1 how to sum the 5 column

    A plain listbox doesn’t have colums.
    I believe you, from a previous thread, use a listbox with tab stops.
    So you have to split all items of the listbox.

    Or better switch to the MSHFlexgrid

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2016
    Posts
    220

    Re: list1 how to sum the 5 column

    as would be an example of the listbox, thanks

  4. #4
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,250

    Re: list1 how to sum the 5 column

    The fundamental issue you seem to be misunderstanding is that VB6 is not a spreadsheet by default (as is Excel).

    The VBA code for Excel is valid but can only work with columns and rows that don't exist in a VB6 listbox. To transfer the code from VBA to VB6 you need to have a structure within your VB6 form that replicates Excel's columns/rows as Arnout suggested - or you change your code to work with a listbox.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2016
    Posts
    220

    Re: list1 how to sum the 5 column

    how can I sum the 5 column in list1 vb 6.0
    thanks

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,904

    Re: list1 how to sum the 5 column

    You can’t, unless you want to do string parsing.
    Where does your data come from, an ado recordset?

  7. #7
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: list1 how to sum the 5 column

    Try this:

    Code:
    Dim I As Integer
    Dim Sum As Double
    
    Sum = 0
        For I = 0 To ListBox1.ListCount - 1
        
            Sum = Sum + Val(Split(ListBox1.List(I), vbTab)(4))   'Column 5
    
        Next I
        TextBox2.Text = Sum

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2016
    Posts
    220

    Re: list1 how to sum the 5 column

    I have not been able to solve it but thank you very much for your answers

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2016
    Posts
    220

    Re: list1 how to sum the 5 column

    thank you very much, Eduardo
    Yes now

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