2016-05-20 5 views
0

Я делаю простой калькулятор калькуляции с помощью Combobox и Label Text. My Combobox имеет 2 позиции: выходные (30.000) и будний день (20.000). В то время как множитель является количеством.Получить значение Combobox в VS

Так что, если я выберу «Выходные (30.000)» в выпадающем списке и введите «2» в qty, результат будет 30.000 * 2 = 60.000.

Я пробовал этот код, но не мог работать.

Интересно, как мне получить значение строк из «Weekend (30.000)» до 30000?

Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged 
     Try 
      lblFinal.Text = cboPrice.SelectedItem * txtQty.Text 
      Catch ex As Exception  
     End Try 
End Sub 



Private Sub cboPrice_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPrice.SelectedIndexChanged 
    Try 
     If cboPrice.SelectedIndex = 1 Then 
      cboPrice.SelectedItem = "30000" 
     ElseIf cboPrice.SelectedIndex = 2 Then 
      cboPrice.SelectedText = "40000" 
     End If 
    Catch ex As Exception 

    End Try 
End Sub 
+1

Пожалуйста, включите опцию Strict. 'lblFinal.Text = cboPrice.SelectedItem * txtQty.Text' умножает время объекта String и присваивает двойной результат строковому свойству – Plutonix

ответ

0

Я попытался снова использовать этот код, и он сработал. , ,

Dim price as integer 

Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged 

     Try 

      lblFinal.Text = Price * CInt(txtQty.Text) 

     Catch ex As Exception 

     End Try 
    End Sub 



    Private Sub cboPrice_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPrice.SelectedIndexChanged 

     Try 
      If cboPrice.SelectedIndex = 0 Then 
       Price = 30000 
      Else 
       Price = 40000 
      End If 
     Catch ex As Exception 

     End Try 
    End Sub