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