Solved

add numbers in listbox

Posted on 1998-06-10
7
405 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
Comment Utility
Edited text of question
0
 

Author Comment

by:440
Comment Utility
Adjusted points to 75
0
 
LVL 1

Accepted Solution

by:
Sekans earned 70 total points
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Expert Comment

by:Sekans
Comment Utility
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
Comment Utility
Sorry, that should be:
For i = 0 To List1.ListCount - 1

Zero, not o

Sekans
0
 

Author Comment

by:440
Comment Utility
works great thanks
0
 
LVL 1

Expert Comment

by:Sekans
Comment Utility
Glad to help
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

743 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