【问题标题】:VB.Net: Display total when check boxes are checkedVB.Net:选中复选框时显示总数
【发布时间】:2015-06-09 14:34:00
【问题描述】:

我正在为游戏制作经验乘数,所以当我输入一个金额时,我会勾选某个乘数,它会乘以我的经验以显示我将获得多少经验。

如果我选中复选框,我希望能够知道如何包含语句,以便包含该语句,否则它不会影响任何内容。

目标: 如果选中系统复选框,我希望我键入的金额(即 exp)乘以 2。其中system = checkbox1 和总 exp 乘以 1.5 倍,如果 'hs = checkbox4' 被选中。如果两者都被选中,总 exp 将乘以 2x1.5= 3。否则,它只是 2x 或 1.5x。但我不知道该怎么做。

例如(我不知道怎么写,但它是我想要的东西)

    system = exp * 2
    hs = exp * (50 / 100)


    If CheckBox1.CheckState = CheckState.Checked Then
        totalexp INCLUDES multiplier system
    ElseIf CheckBox1.CheckState = CheckState.Unchecked Then
        totalexp is not affected by multiplier system
    End If
    If CheckBox4.CheckState = CheckState.Checked Then
        totalexp INCLUDES multiplier hs
    ElseIf CheckBox4.CheckState = CheckState.Unchecked Then
        totalexp INCLUDES multiplier hs
    End If

    totalexp = hs * system

请帮忙!

【问题讨论】:

  • 如果我理解你的问题,如果选中某个复选框并显示它,你想将你的输入乘以一定的速率,对吗?
  • 是的!没错,如果不选中复选框,它不会影响任何事情。
  • 请检查我的答案,如果它有效,请告诉我。

标签: vb.net visual-studio checkbox include


【解决方案1】:

如果您有TextBox1 作为您的exp 输入,两个复选框分别是CheckBox1CheckBox4,分别用于systemhs,以及一个处理输入的按钮,那么您就可以拥有此代码下面。

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim exp As Double
    If IsNumeric(TextBox1.Text) Then
        exp = CDbl(TextBox1.Text)
    Else
        MsgBox("Please input a number.")
    End If
    If CheckBox1.Checked = True Then
        exp = exp * 2
    End If
    If CheckBox4.Checked = True Then
        exp = exp * 1.5
    End If
    If exp <> 0 Then
        MsgBox(exp)
    End If
End Sub
End Class

如果两个复选框都被选中,那么您的输入 (exp) 将乘以 2 AND 1.5。

如果两个复选框均未选中,则显示消息将为零。如果您希望一旦没有选中复选框就不会显示任何消息,那么您可以在最后一个 End If 代码之后添加它

MsgBox(exp)改成

If exp<> 0 Then
    MsgBox(exp)
End If

【讨论】:

  • 我试过了,但是当两个复选框都被选中时,我希望 exp 输入乘以两者,即 2 x 1.5 = 3 但它在这里不起作用
  • 是的,它现在可以工作了,但是我可以问一下如果我添加更多的乘数,它仍然可以工作吗?
  • 是的。只需遵循上面提供的代码的概念。顺便说一句,如果有帮助,请接受我的回答。
  • 是的,当然!但是如何更改消息框以为此标记文本?
  • 只需添加一个标签并以这种方式执行例如>> label1.Text = exp
猜你喜欢
  • 1970-01-01
  • 2016-02-23
  • 1970-01-01
  • 2016-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-05
相关资源
最近更新 更多