Solved

add numbers in listbox

Posted on 1998-06-10
7
458 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
message box in access 4 55
Hide vba in gp 7 125
VBA: copy range dynamically based on config sheet v3 6 53
Win 10 Automation Error with .doCmd in Access 2 82
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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

738 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