Yon Yon - 4 months ago 7
Vb.net Question

Combo Box Drop down list to change a variable

I am creating a program with a Drop Down-list combo Box which contain items a,b,c,d. What i'm willing to do is when i select one item in the combo Box and then clicked a button, the x variable will change. For example when i select b in Combo Box, the x value will change into 2. I needed the variable for another function. how can i change the x variable?

Answer
If ComboBox1.SelectedItem.ToString = "a" Then
    x = 1
ElseIf ComboBox1.SelectedItem.ToString = "b" Then
    x = 2
ElseIf ComboBox1.SelectedItem.ToString = "c" Then
    x = 3
ElseIf ComboBox1.SelectedItem.ToString = "d" Then
    x = 4
End If

Assuming x is an Integer

Comments