Question Problem with what I thought was a simple problem

Jay P

New member
Joined
Mar 31, 2011
Messages
3
Programming Experience
Beginner
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:

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:
Here's the problem:
A local recording studio rents its facilities for $200 per hour, but charges only for the number of minutes used. Your form should allow input of the name of the group and the number of minutes used in the studio. Your program should calculate (and display) the recording charge for this session, as well as accumulate the total charges for all groups.
Display summary information in a group box. Display the total charges for all groups, the total number of groups, and the average charge per group. Format all output appropriately. Include Calculate, Clear for Next Group (does not clear summary info), and Exit buttons. Do not allow bad input to cancel the program.

Sorry I was half asleep from working on this thing. I check radio button 1 and enter the data it works beautifully. When I hit clear check radio button 2 or 3 I have to enter the numbers two different times to get the correct answer. Sometimes when I input a number it will give me $0.00 or a false amount.
 
Well I initially had the radio button on there to control the text boxes I haven't figured out how to enter info into a text box have that information go to one field and then enter different information into that same text box and have it display below the previous information. For example when entering a name using a single textbox to display different names in a table or something to that effect. I did get a 110 on this assignment. My instructor is not very helpful so I am trying to figure this out on my own. I have a very long way to go. Thanks for ur replies I will keep working and hopefully one of these days I will make sense when asking for help lol.
 
Back
Top