我需要帮助从ListBox(标记为lstAge)获取输入。我需要知道,所以我可以将其转换为双精度,因为我想为要使用的值制作一个If语句。如果有帮助,我会附上我所拥有的。
'''
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For count As Double = 16 To 100
count = lstAge.Items.Add(count.ToString())
Next
lstAge.SelectedIndex = 0
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim age As Double
If txtTicket.Text = "N" Or txtTicket.Text = "n" Then
If age < 30 Then
lblResult.Text = txtName.Text & ", your insurance cost will be $45. Keep Up the good driving!"
Else
lblResult.Text = txtName.Text & ", your insurance cost will be $30."
End If
Else
lblResult.Text = txtName.Text & ", your insurance cost will be $85."
End If
End Sub
'''
尝试这样:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For count As Double = 16 To 100
count = lstAge.Items.Add(count.ToString())
Next
lstAge.SelectedIndex = 0
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim age As Double
age = CDbl(lstAge.SelectedItem.ToString())
If txtTicket.Text = "N" Or txtTicket.Text = "n" Then
If age < 30 Then
lblResult.Text = txtName.Text & ", your insurance cost will be $45. Keep Up the good driving!"
Else
lblResult.Text = txtName.Text & ", your insurance cost will be $30."
End If
Else
lblResult.Text = txtName.Text & ", your insurance cost will be $85."
End If
End Sub
在Button1_Click
函数中,age
通过使用ListBox.SelectedItem获取列表框中所选项目的值,将其转换为字符串,然后使用CDbl将其转换为双精度值来进行设置。
这假定您的列表框没有多列,并且您一次选择一项。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句