|
-
Oct 9th, 2000, 05:01 PM
#1
Thread Starter
Lively Member
Easily, how can I add up numeric values in a listbox and display the total in a text field.
i.e lets say this is my list box
------------------
0.75
0.95
1.25
3
1.55
------------------
how can the total or sum be found.
-
Oct 9th, 2000, 05:07 PM
#2
Frenzied Member
Code:
dim counter as integer
dim tempAnswer as integer
tempAnswer = 0
for counter = 0 to 4
List1.listindex = counter
TempAnswer = tempanswer + val(list1.text)
next counter
text1.text = tempanswer
I didn't have time to test that so I hope it works
-
Oct 9th, 2000, 05:09 PM
#3
Frenzied Member
Code:
dim counter as single
dim tempAnswer as single
tempAnswer = 0
for counter = 0 to 4
List1.listindex = counter
TempAnswer = tempanswer + val(list1.text)
next counter
text1.text = tempanswer
I didn't test it but it should be singles instead of integers
NXSupport - Your one-stop source for computer help
-
Oct 9th, 2000, 05:21 PM
#4
Frenzied Member
woops, didn't notice that thanks dimava
-
Oct 9th, 2000, 05:23 PM
#5
Thread Starter
Lively Member
why??????????
why is the "counter = 0 to 4", why is it 0 to 4??
-
Oct 9th, 2000, 05:33 PM
#6
Lively Member
It is 0 to 4 because you have 5 values in your listbox and the listindex starts with 0, therefore you have 0 to 4. To account for all 5 values.
-
Oct 9th, 2000, 05:39 PM
#7
Thread Starter
Lively Member
in reply what if the number of values are undetermined
yes but what if the number on items in the listbox are undetermined and are added to everytime.
the reason i say is because i am working or a program used to keep a total of daily sales made in a store. so everytime a receipt is calculated the total is added to the this listbox and this happens everytime a new receipt is calculated, in turn i need to calculate a daily total, for that i must find a way of adding all the values in the listbox and displaying a daily total in the text field.
thanks
-
Oct 9th, 2000, 05:45 PM
#8
Lively Member
In that case you would use 0 to list1.ListCount instead of some number. The ListCount property gives you the number of values in your Listbox. So you would say counter = 0 to List1.ListCount
-
Oct 9th, 2000, 08:19 PM
#9
Member
You will use
counter = 0 to List1.ListCount-1
listcount starts at 1 while the list starts at 0.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|