[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

add numbers in listbox

Posted on 1998-06-10
7
Medium Priority
?
477 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 280 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
Industry Leaders: 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!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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