みなさん、ユーザーがトラック バー (スライダー コントロール) を変更したときに表示されるメッセージ ボックスを作成するコードがあります。いくつかの計算を行い、ユーザーがアプリケーションに合格したか失敗したかを確認します。問題は、24 時間後に水が 100 を超えたときに、ユーザーが通過したことを知らせるメッセージ ボックスが表示されることを、私のロジックが考慮していないことです。しかし、開始額が 500 の場合、アプリケーションは自動的にユーザーが通過したと見なし、メッセージを表示しません。2 番目の if ステートメントをコメント アウトしました。コメント アウトしていない場合は、そこから始まるからです。助けてくれてありがとう!
これが私のコードです:
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim Gallons As Double = 500 'Constant Starting amount
Dim LeakRate As Double = 0.1 'Constant leak for 24hr
Dim Remainder As Integer 'Creating a variable
Dim Time As Integer = tkbSlider.Value 'Gets the Value of the Slider or Track Bar
lstRemainingGallons.Items.Clear() 'Clears the Collection of ListBox
Try
For n As Integer = 1 To 24 'Setting Up the Loop
Remainder = CInt(Gallons * LeakRate) - Time 'Math Calculation
Gallons = CInt(Gallons - Remainder) 'More Math
If Gallons <= 99 Then 'Displaying Message
MessageBox.Show("Fish died at " & n & " hours when the remaining gallons were " & Gallons, "Dead and Stinking Fish", MessageBoxButtons.OK
)
Exit Sub
End If
'If Gallons > 100 Then 'Displaying Message
'MessageBox.Show("Get out the BBQ! You made it!", "Fish Frying Time!")
'End If
lstRemainingGallons.Items.Add("Hour # " & n & " - " & Gallons & "gallons")
Next
Catch ex As Exception ' Catching an Execption if any?
End Try
End Sub
End Class