Solved

add numbers in listbox

Posted on 1998-06-10
7
417 Views
Last Modified: 2008-02-01
if i have numbers in a list box say (5,2,8,2,1) is there a way to press a command button and add these numbers together to eqaul (18) and show them in a label or textbox and is it possible to copy all the selected items from one list to another list box
0
Comment
Question by:440
  • 4
  • 3
7 Comments
 

Author Comment

by:440
ID: 1463003
Edited text of question
0
 

Author Comment

by:440
ID: 1463004
Adjusted points to 75
0
 
LVL 1

Accepted Solution

by:
Sekans earned 70 total points
ID: 1463005
440
Try this:

Private Sub Command1_Click()
Dim i As Integer, totnum As Integer
For i = o To List1.ListCount - 1
    List1.ListIndex = i
    totnum = totnum + List1.Text
Next i
MsgBox totnum
End Sub    

Regards,
Sekans
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:Sekans
ID: 1463006
I think I was submitting my answer while you were editing the question.  So here is the revised answer.  

Dim i As Integer, totnum As Integer
For i = o To List1.ListCount - 1
    List1.ListIndex = i
    List2.AddItem List1.Text         'This will add the selected item in List1 to List2
    If IsNumeric(List1.Text) = True Then   'This checks to be sure   it is numeric before adding to the total
        totnum = totnum + List1.Text
    End If
Next i
Label1.Caption = totnum     'This displays the total in Label1

Regards,
Sekans
0
 
LVL 1

Expert Comment

by:Sekans
ID: 1463007
Sorry, that should be:
For i = 0 To List1.ListCount - 1

Zero, not o

Sekans
0
 

Author Comment

by:440
ID: 1463008
works great thanks
0
 
LVL 1

Expert Comment

by:Sekans
ID: 1463009
Glad to help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now