VB.net: How to make original variable value fulfill 2 statements?

79 views Asked by At

I am creating an EXP multiplier and I do not know how to make the original variable do be separated to do fulfill 2 statements.

Aim:
I want it so that when checkbox1.checked = true checkbox2.checked = true checkbox5.checked = true, and the input = 2, then the answer will be 2 x 2x1.5 + 2 x 1.1 = 8.2 NOT 2 x 2x1.5x1.1 which gives me 6.6.

However, I tried using the separator to separate them, then add them together in the result as exptotal, but I made a mistake using exp2 with exp as inputs, as the answer is now 2 x 2x1.5 + 2 + 2 x 1.1 as my code writes exp + exp2 and exp2 is also an input so the result is now 8.2 instead of 6.2 with that extra input.

I do not know how to get around so that i can use the ORIGINAL exp such that exp2 = (exp * 1.1) without using the exp from checkbox1 and checkbox2

My code:

dim exp as double
dim exp2 as double
dim exptotal as double
If IsNumeric(TextBox9.Text) Then
        exp = CDbl(TextBox9.Text)
    Else
        MsgBox("Please input a number.")
    End If
    If CheckBox1.Checked = True Then
        exp = exp * 2
    End If
    If CheckBox2.Checked = True Then
        exp = exp * 1.5
    End If
    If CheckBox5.Checked = True Then
        exp2 = exp2 * 1.1
    End If

    exptotal = exp + exp2

This code makes the result includes the input 2 again as totalexp = exp + exp2 which is not what I want. I want to get rid of that extra input but still having the checkbox5 statement being ADDED together with checkbox1 and checkbox2 NOT multiplied. But I do not know how to do that. This is the closest I can come to. I hope you can understand me!

I am very confused right now, please help!!

1

There are 1 answers

0
the_lotus On

Reading your question is soo confusing. Your variable also don't tell any story, what is CheckBox1, TextBox9 ? These are bad variable name.

Since your not telling what the logic should be but only talk about one scenario, I have to guess.

Dim input, total As Double

total = 0

If Not Double.TryParse(TextBox9, input) then
    MessageBox.Show("Please input a number.")
Else
    Dim part1, part2 As Double

    part1 = 0
    part2 = 0

    If CheckBox1.Checked = True And CheckBox2.Checked = True Then
        part1 = 3
    Else If CheckBox1.Checked = True Then
        part1 = 2
    Else If CheckBox2.Checked = True Then
        part1 = 1.5
    End If

    If CheckBox5.Checked = True Then
        part2 = 1.1
    End If

    total = (input * part1) + (input * part2)
End If