2016-05-20 7 views
0

私はコンボボックスとラベルのテキストを使って簡単な価格計算機を作っています。 Myコンボボックスには、週末(30.000)と平日(20.000)の2つのアイテムがあります。乗数は数量ですが。VSでコンボボックスの値を取得

したがって、コンボボックスで「週末(30.000)」を選択し、数量に「2」を入力すると、結果は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

Option Strictをオンにしてください。 'lblFinal.Text = cboPrice.SelectedItem * txtQty.Text'は、Object times Stringを掛けて、Double結果を文字列プロパティに代入します。 – 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 
関連する問題