Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculating numerical values in a list box

Status
Not open for further replies.
not sure what you mean but this should get you started

Code:
Option Explicit

Private Sub Command1_Click()
  Dim i As Long
  Dim nSum As Long
  
  For i = 0 To List1.ListCount - 1
    nSum = nSum + Val(List1.List(i))
  Next i
  
  Text1.Text = nSum
End Sub

Private Sub Form_Load()
  Dim i As Long
  
  For i = 1 To 15
    List1.AddItem i
  Next i
End Sub
 
Hi,

Items in a listbox are strings. To convert a string to a numeric value you can use one of the following

Val()
CInt()
CDec()

e.g.
MyVar = Val(List1.List(0))
Be advised, you should validate the string first to make sure the string doesn't contain non-numeric characters.

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top