# Combo Box Loop • ### Question

• Hi I am trying to make a program that will have a drop down where you can select an amount of days and then have a loop that will double pay amount for each day for example 1=1 2=2 3=4 4=8 8=16

Thanks

Saturday, March 31, 2018 6:05 AM

• I was able to come up with this but I need to be able to select a value from the drop down of type one in

Then you need to use the SelectedText property. But you will need to confirm it is a valid number first, and then convert it to a number before you use it in the calculation.  See: https://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx

However, you haven't indicated the event that you are using for the calculation.  If you want to do this calculation in the selected index changed event or in the selected value changed event then yo won't be able to use the selected text.  Use the SelectedItem property instead and convert it to an integer before using it.

• Marked as answer by Monday, April 2, 2018 7:12 PM
Sunday, April 1, 2018 7:38 AM

### All replies

• Hi I am trying to make a program that will have a drop down where you can select an amount of days and then have a loop that will double pay amount for each day for example 1=1 2=2 3=4 4=8 8=16

Your multiplication factor is 2^(n-1).  For instance:
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8

• Proposed as answer by Saturday, March 31, 2018 10:03 AM
Saturday, March 31, 2018 8:56 AM
• how could I then put that in to a program with a combo box selection list.
Sunday, April 1, 2018 3:18 AM
• how could I then put that in to a program with a combo box selection list.

That depends on what you want to do.  If the user has selected an item in the combobox then you have access to the item that got selected ( SelectedItem ) or the combobox selected index ( SelectedIndex ).  The selected index might be the easiest to use, but that depends on exactly what the items in the combobox are.  Whatever, you have a number that you can then use in the calculation described above.   Exactly how you do that will depend on the design of the application.  If you want more detail you will need to explain how your application is going to work.

Sunday, April 1, 2018 3:33 AM
• I was able to come up with this but I need to be able to select a value from the drop down of type one in Dim Days As Integer
Days = 1

Dim Pennies As Integer
Pennies = 1
For Days = 1 To cboDays.SelectedIndex
Pennies = Pennies * 2
Next Days
lblTotal.Text = Pennies.ToString()
Sunday, April 1, 2018 6:52 AM
• I was able to come up with this but I need to be able to select a value from the drop down of type one in

Then you need to use the SelectedText property. But you will need to confirm it is a valid number first, and then convert it to a number before you use it in the calculation.  See: https://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx

However, you haven't indicated the event that you are using for the calculation.  If you want to do this calculation in the selected index changed event or in the selected value changed event then yo won't be able to use the selected text.  Use the SelectedItem property instead and convert it to an integer before using it.

• Marked as answer by Monday, April 2, 2018 7:12 PM
Sunday, April 1, 2018 7:38 AM