将列表框项绑定到方程式

时间:2013-04-03 10:23:59

标签: vb.net

我是VB 2010的新用户。我正在做一个简单的程序作为我的Uni项目的一部分 该计划的想法是帮助用户找到适合他/她的卡路里的适当的膳食。 计算卡路里时应考虑许多因素。 这些是年龄,体重,身高和活动水平 然后用户应该决定他/她是否想要保持他/她的体重或减肥 基于所有这些输入..应显示膳食

实际上,我构建了程序的形式......我编写了计算BMR的公式,这是计算卡路里之前的一步。尽管取得了这些进展,但我发现难以将“列表框”中的活动级别与等式绑定,其中每个级别表示一个数字以将其添加到等式中。我不知道该怎么办。我应该首先识别列表框的项目还是????

我在网站和youtube上找到了很多资料,但我没有什么需要 我需要你的帮助

这就是我所做的

 If RadioButton1.Checked = True Then
            TextBox1.Text = (66 + (13.7 * MaskedTextBox1.Text) + (5 * MaskedTextBox2.Text) - (6.8 * MaskedTextBox3.Text))
        ElseIf RadioButton2.Checked = True Then
            TextBox1.Text = (665 + (9.6 * MaskedTextBox1.Text) + (1.8 * MaskedTextBox2.Text) - (4.7 * MaskedTextBox3.Text))
        End If

1 个答案:

答案 0 :(得分:0)

您所做的就是:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    If ListBox1.SelectedItem = "This is item 1" Then
        'Do your math here - If you want the first item to be 1
        'then you simply use the number 1 here

        'Example: (Will display 2)
        MsgBox(1 + 1)
    ElseIf ListBox1.SelectedItem = "This is the 2:nd item" Then
        'Do your math here - If you want the first item to be 1
        'then you simply use the number 1 here

        'Example: (Will display 3)
        MsgBox(1 + 2)
    ElseIf ListBox1.SelectedItem = "This is item 3" Then
        'Do your math here - If you want the first item to be 1
        'then you simply use the number 1 here

        'Example: (Will display 4)
        MsgBox(1 + 3)
    End If
End Sub

所以基本上,如果所选项目是加工1 + 1的项目 - 代码将执行“方程式”

如果您想要动态添加项目,还有另一种方法:)