krcostello87
New member
- Joined
- Apr 19, 2010
- Messages
- 1
- Programming Experience
- 1-3
Hey guys gotta quick question for ya. I'm creating a program called Workshop Selector. It has 3 list boxes, one with the 5 workshops, second with 6 locations, and the final is the list of costs. The user selects a workshop, a location, then hits the Add Workshop button, which calculates the costs and adds the cost to the third listbox. Soo, to my question.
There is an additional button called Calculate Total that adds the values of the costs in the cost listbox and displays the total in a textbox. The code i currently have that works just fine is --
Dim one, two, three, four, five, total As Integer
lbCost.SelectedIndex = 0
one = CInt(lbCost.SelectedItem.ToString)
lbCost.SelectedIndex = 1
two = CInt(lbCost.SelectedItem.ToString)
etc..etc..
total = one + two + three + four + five
tbxTotal.text = total
While this works, i have no idea of knowing how many times the user will add a cost to the cost listbox. therefore id have to make many many variables, and other issues occur.
So is there a way i can do this with a for loop? declare a global variable like
Dim costcounter as integer
then at the end of the add workshop cost btn click procedure use:
costcounter = costcounter + 1
That way i kno the exact amount of times the person added a cost?
Then create a for loop like
Dim intcount As Integer
For intcount = 1 To costcounter
code....
Next
Would this work somehow? but what code would i have to input within the for loop to scan each selected index, and then return values that can be added together and displayed in a textbox?
There is an additional button called Calculate Total that adds the values of the costs in the cost listbox and displays the total in a textbox. The code i currently have that works just fine is --
Dim one, two, three, four, five, total As Integer
lbCost.SelectedIndex = 0
one = CInt(lbCost.SelectedItem.ToString)
lbCost.SelectedIndex = 1
two = CInt(lbCost.SelectedItem.ToString)
etc..etc..
total = one + two + three + four + five
tbxTotal.text = total
While this works, i have no idea of knowing how many times the user will add a cost to the cost listbox. therefore id have to make many many variables, and other issues occur.
So is there a way i can do this with a for loop? declare a global variable like
Dim costcounter as integer
then at the end of the add workshop cost btn click procedure use:
costcounter = costcounter + 1
That way i kno the exact amount of times the person added a cost?
Then create a for loop like
Dim intcount As Integer
For intcount = 1 To costcounter
code....
Next
Would this work somehow? but what code would i have to input within the for loop to scan each selected index, and then return values that can be added together and displayed in a textbox?
Attachments
Last edited by a moderator: