如何从Visual Basic的列表框中获取用户输入?

乔纳森·C

我需要帮助从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

'''

sbgib

尝试这样:

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何获取用户输入并查看它是否在列表中

如何从文本框输入中填充用户窗体列表框/组合框数组/列表?

如何获取输入的列表框项目

将文本框输入存储到数组中并将其显示在 Visual Basic 中的列表框中

如何从用户窗体列表框中的 0+n 列中获取文本?

R Shiny:如何从DT数据表的搜索框中获取用户输入?

如何从jquery ui对话框中获取用户输入

如何从 Visual Basic 中的列表框中选择一个随机项目

如何从用户选择的列表框中获取字符串值?

如何加载 tkinter 的入口小部件中的 url,该 url 与列表框中列表的已保存用户输入链接?

Visual Studio,如何使文件显示在列表框Powershell中

如何使用MVVM管理列表框中的用户控件?

如何从HTML服务中的列表框中获取值

如何从顶级组合框中获取用户选择的选项

如何获取用户输入并将其存储在向量中?

如何在 Hadoop 2.7.5 中获取用户输入?

如何在 Python 中获取用户输入?

如何在applescript中获取用户语音输入

如何使用 HTML 获取用户输入以在 JS 中处理?

如何从for循环索引的标准输出中获取用户输入

如何在fopen中获取用户输入

如何从不同的类中获取用户输入

如何在节点js中获取用户输入?

如何从反射域列表框中获取DoubleClicked事件

如何从列表框delphi中的特定行获取文本

如何从列表框中获取字符串

如何在tkinter的列表框中获取每个项目?

Visual Basic.Net停止用户选择列表框项目

我如何从文本框中获取用户输入以在倒计时脚本中使用它?