Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

:confused: I am writing an estimating software with VB.NET. I need to know the code to add up all the numbers in a listbox.

 

If i have:

 

5

4

7

 

in ONE listbox, i need to know the code to put for the button to add them up!

 

Please reply or preferably email me atemail me

  • *Experts*
Posted
Dim runningTotal As Int32 = 0
Dim s As String

For Each s In ListBox1.Items
 Try
   runningTotal += Int32.Parse(s)
 Catch
 End Try
Loop

That should do it. It just iterates the listbox and attempts to add the value to runningTotal.

  • *Experts*
Posted

Other than the fact that I accidentally put Loop instead of Next at the end of the For loop, my code does exactly that.

 

Just display runningTotal in a textbox.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...