Results 1 to 5 of 5

Thread: adding values of a list box..

  1. #1

    Thread Starter
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Lightbulb adding values of a list box..

    hi ..

    this buddy getting small problem with list box..

    I hv a listbox which stores some values..(gets values from a table)

    when ever the listbox is refreshed ,I have to add (sum) all the values which are there in the listbox and i have to show that value in a text box..

    I think u ppl got my prob...is there any simple way to get it..????

    plz chk it..

    thanx & regards
    Anu..

  2. #2
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: adding values of a list box..

    VB Code:
    1. Dim i As Integer
    2.     Dim sum As Integer
    3.     For i = 0 To List1.ListCount - 1
    4.         sum = sum + CInt(List1.List(i))
    5.     Next i
    6.     Text1.Text = sum

  3. #3

    Thread Starter
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: adding values of a list box..

    hi rob,

    Is there any direct function for this...I heared that there was a direct function that wil gives like the same..

    thanx & regards
    Anu.

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: adding values of a list box..

    I suggest u don't use the listbox to sync the textbox. Instead fill it directly by querying the database whenever the listbox is refreshed using query like this

    SELECT SUM(FieldName) FROM TableName

    That would be faster and easier than iterating through the listbox.

    EDIT: u can use Connection.Execute to execute the query

  5. #5

    Thread Starter
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: adding values of a list box..

    thats really good idea..

    thanx pradeep..

    Anu.

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