2015-10-15 55 views
-1

我在第一次使用VB中的單選按鈕,我無法弄清楚我做錯了什麼。單擊事件是假設乘兩個輸入,但不管什麼不圖輸入,結果回來0Visual Basic單選按鈕計算

我一起工作的代碼:

Dim decTotal As Decimal  'Total charge for choice plan 

Dim intMinutes As Integer   'Duration of phone calls 
  
'Declare constants for Rates 

Const decDaytimeRate As Decimal = 0.07D 

Const decEveningRate As Decimal = 0.12D 

Const decOffPeakRate As Decimal = 0.05D 
  
'Dispay Total charge 

lblTotal.Text = decTotal.ToString("c") 
  
  
  

'Calculate total amount the user is expected to pay according to rate plan 

If radDaytime.Checked = True Then 

decTotal = intMinutes * decDaytimeRate 

End If 

If radEvening.Checked = True Then 

decTotal = decEveningRate * intMinutes 

End If 

我相信這是一個簡單的解決方案,因爲我不會拋出任何錯誤消息,但我仍然陷入困境。

+0

你是什麼意思「結果回來」單擊事件不返回一個值。請格式化您的代碼 – Plutonix

+0

是的,這就是我的意思。點擊計算按鈕時的結果返回0.00值。 – cybagem

+0

在進行計算之後設置lblTotal.Text屬性**,而不是之前。 –

回答

0

將lblTotal.Text = decTotal.ToString(「c」)行移至末尾。它在計算之前顯示結果。

+0

非常感謝。在計算後設置它是非常有意義的,但結果仍然相同。 – cybagem

+0

將intMinutes更改爲小數。我認爲問題在於VB將十進制數四捨五入爲int(0),所以任何被0重複的值都是0。或者,您可以將intMinutes保留爲Int,但在Decimal.Parse(intMinutes)計算中包含intMinutes :例如decTotal = decEveningRate * Decimal.Parse(intMinutes) – Sam

+0

另一個說明:你在哪裏設置intMinutes?目前它也是0 ... – Sam