[英]Using Radio Buttons in Microsoft Visual Studio 2012 - Coding error
出於某種原因,當我調試時第一個“ If”語句起作用,但是當我嘗試使用任何其他單選按鈕或使用相同的按鈕但嘗試使第二個“ If”語句為真時,我單擊了“計算獎勵積分”按鈕,但是不計算。 它僅計算第一個“ If”語句。 這是我的代碼。 如果我的行話達不到標准,我深表歉意。 我上這堂課是因為這是必需的。 我隨隨便便
公開課表格1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Const basic1 As Double = 0.03
Const basic2 As Double = 0.05
Const basic3 As Double = 0.08
Const basic4 As Double = 0.1
Const basic5 As Double = 0.15
Dim totalLabel As Double
Dim doubleReward As Double
Double.TryParse(RewardDisplay.Text, doubleReward)
Double.TryParse(TotalTextBox.Text, totalLabel)
If basicRadioButton.Checked AndAlso totalLabel < 100 Then
RewardDisplay.Text = totalLabel * basic1
ElseIf basicRadioButton.Checked AndAlso totalLabel < 200 or >= 100 Then
RewardDisplay.Text = totalLabel * basic2
ElseIf basicRadioButton.Checked AndAlso totalLabel >= 200 Then
RewardDisplay.Text = totalLabel * basic3
ElseIf standardRadioButton.Checked AndAlso totalLabel < 199 Then
RewardDisplay.Text = totalLabel * basic3
ElseIf standardRadioButton.Checked AndAlso totalLabel >= 200 Then
RewardDisplay.Text = totalLabel * basic4
ElseIf premiumRadioButton.Checked AndAlso totalLabel < 299 Then
RewardDisplay.Text = totalLabel * basic4
ElseIf premiumRadioButton.Checked AndAlso totalLabel >= 300 Then
RewardDisplay.Text = totalLabel * basic5
End If
End Sub
您必須在調試模式下查看變量basicRadioButton.Checked和totalLabel的值,以了解該算法為何不符合您的期望。 簡化您的代碼,也許要做一些鏈接
If basicRadioButton.Checked then
'the totalLabel conditions now
end if
if standardRadioButton.Checked then
'the totalLabel conditions now
end if
if premiumRadioButton.Checked then
'the totalLabel conditions now
end if
這將幫助您找到錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.