2016-05-20 10 views
0

Ich mache einen einfachen Preisrechner mit einer Combobox und Label Text. Meine Combobox hat 2 Artikel: Wochenende (30.000) und Wochentag (20.000). Während der Multiplikator die Menge ist.Get Combobox Wert in VS

Also, wenn ich "Wochenende (30.000)" in der Combobox und Eingabe "2" zu Menge, das Ergebnis wäre 30.000 * 2 = 60.000.

Ich habe diesen Code versucht, konnte aber nicht funktionieren.

Ich frage mich, wie bekomme ich den Wert der Strings von "Weekend (30.000)" auf 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

Bitte aktivieren Sie Option Strict. 'lblFinal.Text = cboPrice.SelectedItem * txtQty.Text' multipliziert das Objekt mit Times String und weist das Double-Ergebnis einer String-Eigenschaft zu – Plutonix

Antwort

0

Ich versuchte es erneut mit diesem Code und es funktionierte. . .

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