# listbox codes

### Question

• I have to make a form that has three list boxes.
First list box has workshop names
Second list box has location names
Third list box will display the workshop with costs and days to attend along with the location and the cost multiplied by the number of days of the workshop chosen.
I have 4 buttons
add workshop button that will show the selected items from listbox 1 & 2 and their respected costs
calculate total button that will add all the different workshops chosen with their respected locations and display the total in a label box
reset button
exit button

I can figure out where to start.
My instructor says all we need is to define the variables (5 minimum) and use an If... Then... ElseIf... statement to add the items to the listbox.

Thursday, February 26, 2009 6:59 PM

• The problem with these types of questions is that your instructor has some specific point they are trying to teach.  The actual project may be built poorly, but demonstrate the technique as intended.

There is no indication of how the list of names are meant to be related to the other data.  For instance, if the Workshop listbox only contains a list of workshop names, how do you know how many days the workshop is supposed to be or what its cost is?

The one thing I am sure of is that what I would suggest you do, is not what your instructor intends for you to do.  Because it sounds like you need to create a Workshop class and add instances of that class to the listbox.  But your course may not be at the point of writing your own classes yet...

One guess is that you are supposed to hard-code the values of the number of days and price into this If-Then statement...  like I said, homework projects are usually terrible applications from a design point-of-view, but then again they are only meant to demonstrate a specific concept - and we don't know what yesterday's lecture was about!  :)

If my guess is correct, then perhaps you are supposed to do something like:

 Dim workshopLength As Integer Dim workshopCost As Double If ListBox1.SelectedIndex = 0 Then 'Set values for workshop #1 workshopLength = 3 'three days workshopCost = 750.0 '\$750.00 for the workshop ElseIf ListBox1.SelectedIndex = 1 Then 'Set values for workshop #2 workshopLength = 1 workshopCost = 125.0 ElseIf ListBox1.SelectedIndex = 2 Then 'Continue this for each possible works ElseIf ListBox1.SelectedIndex = -1 Then 'no workshop was selected 'perhaps show a message and exit sub End If

Then after you've figured out all your variable values you can create a string that contains all the correct output information.  This example only created 2 variables and apparently the assignment calls for at least 5 to hold all the required info.

Again, I'm just guessing that this is what you are supposed to do.  I would suggest that you confer with fellow classmates and see what they think the instructions mean...

Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
• Marked as answer by Friday, February 27, 2009 7:53 PM
Thursday, February 26, 2009 8:19 PM

### All replies

• The problem with these types of questions is that your instructor has some specific point they are trying to teach.  The actual project may be built poorly, but demonstrate the technique as intended.

There is no indication of how the list of names are meant to be related to the other data.  For instance, if the Workshop listbox only contains a list of workshop names, how do you know how many days the workshop is supposed to be or what its cost is?

The one thing I am sure of is that what I would suggest you do, is not what your instructor intends for you to do.  Because it sounds like you need to create a Workshop class and add instances of that class to the listbox.  But your course may not be at the point of writing your own classes yet...

One guess is that you are supposed to hard-code the values of the number of days and price into this If-Then statement...  like I said, homework projects are usually terrible applications from a design point-of-view, but then again they are only meant to demonstrate a specific concept - and we don't know what yesterday's lecture was about!  :)

If my guess is correct, then perhaps you are supposed to do something like:

 Dim workshopLength As Integer Dim workshopCost As Double If ListBox1.SelectedIndex = 0 Then 'Set values for workshop #1 workshopLength = 3 'three days workshopCost = 750.0 '\$750.00 for the workshop ElseIf ListBox1.SelectedIndex = 1 Then 'Set values for workshop #2 workshopLength = 1 workshopCost = 125.0 ElseIf ListBox1.SelectedIndex = 2 Then 'Continue this for each possible works ElseIf ListBox1.SelectedIndex = -1 Then 'no workshop was selected 'perhaps show a message and exit sub End If

Then after you've figured out all your variable values you can create a string that contains all the correct output information.  This example only created 2 variables and apparently the assignment calls for at least 5 to hold all the required info.

Again, I'm just guessing that this is what you are supposed to do.  I would suggest that you confer with fellow classmates and see what they think the instructions mean...

Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
• Marked as answer by Friday, February 27, 2009 7:53 PM
Thursday, February 26, 2009 8:19 PM
• I believe what you wrote is probably what she is after. I will work with that. The challenge does give me length and cost for each workshop and cost per day for each location. I know I can work with what you have offered me. I guess I was just thinking too much into this one. It doesn't seem that difficult. I appreciate your reply. It will help me a lot. Thank you so much.
Thursday, February 26, 2009 9:05 PM
• I'm not sure you'll find a coder here who isn't guilty of over-thinking a solution at one point or another!

Hope that does help, and good luck!

P.S.  Be sure to participate in our answer system by clicking the Mark as Answer button on any post(s) which you feel answered your question.  Thanks!
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
Thursday, February 26, 2009 9:50 PM