2015-06-09 76 views
-2

我正在創建一個EXP乘數,並且我不知道如何使原始變量分開來完成2個語句。VB.net:如何使原始變量值滿足2條語句?

目的:
我希望它這樣,當checkbox1.checked = truecheckbox2.checked = truecheckbox5.checked = trueinput = 2,那麼答案將是2 x 2x1.5 + 2 x 1.1= 8.22 x 2x1.5x1.1這給了我6.6

不過,我嘗試使用分離器將它們分開,然後在結果加在一起他們爲exptotal,但我做到了使用exp2時犯的錯誤exp的投入,現在答案2 x 2x1.5 + 2 + 2 x 1.1是我的代碼寫入exp + exp2exp2 is also an input,所以結果現在是8.2而不是6.2與該額外的輸入。

我不知道怎麼去解決,這樣我可以使用原來的exp這樣exp2 = (exp * 1.1)不使用來自checkbox1expcheckbox2

我的代碼:

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 

這段代碼的結果包括輸入2再次爲totalexp = exp + exp2這不是我想要的。我想擺脫額外的輸入,但仍然會將checkbox5語句與checkbox1checkbox2不相乘。但我不知道該怎麼做。這是我可以最接近的。我希望你能理解我!

我現在很困惑,請幫助!

+1

這與你的[上一個問題](http://stackoverflow.com/q/30726319/1070452)有什麼不同? – Plutonix

+1

我不太明白什麼是錯的。當一切都爲真時,這應該返回exp * 2 * 1.5 + exp2 * 1.1。這不是你想要的嗎? – Sastreen

+0

不,這是儘可能接近我的答案,這是增加兩個值來獲得'exptotal'但是我意識到自從最後一個問題以來我在做什麼,我想說更好,因爲沒有解決方案給我最後一個問題。所以這就是我想要做的事情'exp * 2 * 1.5 + exp2 * 1.1'給了我'10.2',但我想它是'8.2',我不想添加兩個值,但只添加一個,但我不知道該怎麼做,這是最接近我可以來。我只想使用第一個值來得到1.1,如果輸入是2但不與其他乘法,但似乎我不能這樣做。 – pleasega

回答

0

讀你的問題是太混亂。你的變量也不告訴任何故事,什麼是CheckBox1,TextBox9?這些是錯誤的變量名稱。

既然你不告訴邏輯應該是什麼,而只是談論一個場景,我不得不猜測。

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