Solved

add numbers in listbox

Posted on 1998-06-10
7
432 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

786 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