I have been working on this assignment for class and I am getting a logical error. I think my problem is with the try catch exception. I am pretty new at this and have tried working through it and the exact problem eludes me. I have tried setting a break point, but no luck so far. I am mainly looking for what's wrong any help would be greatly appreciated.
Here's the code:
Here's the code:
VB.NET:
Public Class records
Private ChargePerMinute As Decimal = (ChargePerHour / 60)
Private MinutesUsedFirst As Decimal
Private MinutesUsedSecond As Decimal
Private MinutesUsedThird As Decimal
Const ChargePerHour As Decimal = 200
Private Sub RButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RButton1.CheckedChanged
GroupNameTxtBox2.Visible = False
GroupNameTxtBox3.Visible = False
GroupLabel2.Visible = False
GroupLabel3.Visible = False
Minutes2TextBox.Visible = False
Minutes3TextBox.Visible = False
End Sub
Private Sub RButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RButton2.CheckedChanged
GroupNameTxtBox3.Visible = False
GroupNameTxtBox2.Visible = True
GroupLabel2.Visible = True
GroupLabel3.Visible = False
Minutes2TextBox.Visible = True
Minutes3TextBox.Visible = False
End Sub
Private Sub RButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RButton3.CheckedChanged
GroupNameTxtBox2.Visible = True
GroupNameTxtBox3.Visible = True
GroupLabel2.Visible = True
GroupLabel3.Visible = True
Minutes2TextBox.Visible = True
Minutes3TextBox.Visible = True
End Sub
Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
Dim TotalCharges As Decimal = (MinutesUsedFirst + MinutesUsedSecond + MinutesUsedThird) * (ChargePerMinute)
Dim AverageCharge As Decimal = (TotalCharges) / 3
Dim PlusTwo As Decimal = (MinutesUsedFirst * ChargePerMinute) + (MinutesUsedSecond * ChargePerMinute)
Dim AverageTwo As Decimal = PlusTwo / 2
If RButton1.Checked Then
Try
MinutesUsedFirst = Minutes1TextBox.Text
Catch NoData As InvalidCastException
MessageBox.Show("Please enter the number of minutes in the session.")
End Try
Minutes1TextBox.Text = MinutesUsedFirst
TotalTextBox.Text = (MinutesUsedFirst * ChargePerMinute).ToString("C")
AVGTextBox.Text = (MinutesUsedFirst * ChargePerMinute).ToString("C")
NumberTextbx.Text = "1"
ElseIf RButton2.Checked Then
Try
MinutesUsedSecond = Minutes2TextBox.Text
Catch NoData As InvalidCastException
MessageBox.Show("You have been warned numbers only.")
End Try
Minutes2TextBox.Text = MinutesUsedSecond
TotalTextBox.Text = PlusTwo.ToString("C")
AVGTextBox.Text = AverageTwo.ToString("C")
NumberTextbx.Text = "2"
ElseIf RButton3.Checked Then
Try
MinutesUsedThird = Minutes3TextBox.Text
Catch NoData As InvalidCastException
MessageBox.Show("Step away slowly this...Nevermind I doubt you have any literacy skill whatsoever.")
End Try
Minutes3TextBox.Text = MinutesUsedThird
TotalTextBox.Text = TotalCharges.ToString("C")
AVGTextBox.Text = AverageCharge.ToString("C")
NumberTextbx.Text = "3"
End If
LizardTimer.Enabled = True
LizardBlurTimer.Enabled = True
LizardDarkTimer.Enabled = True
StopButton.Visible = True
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
StopButton.Visible = False
Minutes2TextBox.Visible = False
Minutes3TextBox.Visible = False
GroupNameTxtBox2.Visible = False
GroupNameTxtBox3.Visible = False
GroupLabel2.Visible = False
GroupLabel3.Visible = False
With RButton1
.Focus()
.Visible = True
End With
GroupNameTxtBox1.Clear()
GroupNameTxtBox2.Clear()
GroupNameTxtBox3.Clear()
Minutes1TextBox.Clear()
Minutes2TextBox.Clear()
Minutes3TextBox.Clear()
TotalTextBox.Clear()
NumberTextbx.Clear()
AVGTextBox.Clear()
End Sub
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub
Private Sub LizardTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LizardTimer.Tick
Lizard.Visible = True
LizardBlur.Visible = False
LizardDark.Visible = False
End Sub
Private Sub LizardBlurTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LizardBlurTimer.Tick
Lizard.Visible = False
LizardBlur.Visible = True
LizardDark.Visible = False
End Sub
Private Sub LizardDarkTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LizardDarkTimer.Tick
Lizard.Visible = False
LizardBlur.Visible = False
LizardDark.Visible = True
End Sub
Private Sub StopButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopButton.Click
LizardTimer.Enabled = False
LizardBlurTimer.Enabled = False
LizardDarkTimer.Enabled = False
End Sub
End Class
Last edited by a moderator: