VB.Net: Display total when check boxes are checked

1.4k views Asked by At

I am making a EXP multiplier for a game, so when i key in an amount, i will tick the certain multiplier and it will multiply my EXP to display how much EXP i will earn.

I want to be able to know how to include statement if i check the checkbox so that the statement will be included, else it will not affect anything.

AIM: i want the amount that i key in, which is exp, to multiply by 2 if system checkbox is checked. In which system = checkbox1 and the total exp to multiply by 1.5x if 'hs = checkbox4' is checked. And if both is checked, total exp will multiply by 2x1.5= 3. Else, it is just 2x or 1.5x. But i do not know how to do that.

For example(i do not know how to write it but it is something around the point i want)

    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

Please help!

1

There are 1 answers

5
MAC On BEST ANSWER

Providing you have TextBox1 as your exp input and two check boxes which are CheckBox1 and CheckBox4 for system and hs respectively and a button to process the input then you can have this code below.

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

If both check boxes are checked then your input (exp) will be multiplied by 2 AND 1.5.

If neither of the check boxes are checked, the display message will be zero. If you want that no message will be displayed once there will be no check box checked then you can add this right after the last End If code

change MsgBox(exp) to

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