Need Help With Visual Basic Homework, Try-catch?

Alright, so I am supposed to do this project for homework and I need a Try-Catch function in there. I already made the program but I dont know how exactly to add in this function. Here is the assignment:
1. The user first views a Windows form that displays the campground name, a picture of the campground, a ComboBox object requesting the type of site: tent site $20 a night, RV site $35 a night, or cabin rental $55 a night, the number of nights(TextBox object), and if they have one of the following discounts: AAA (10%) or Military (12%).
2. After the information has been entered, a Sub procedure displays the labels: Subtotal Billing Amount for Your Stay, Taxes for Your Stay, and Final Total.
3. Pass the cost of the type of camping site and the number of nights to a Sub procedure to calculate the subtotal of the camp site. Do not display the amount in this procedure.
4. Pass the subtotal and the discount amount to the Function procedure. Determine the subtotal based on the type of discount. Pass the amount back to the calling method.
5. Another Function procedure should compute the 7.5% tax. Pass that value back to the calling method.
6. Pass the subtotal, tax, and final cost to a Sub procedure to display the results.
7. The input values should be validated in a separate procedure by a Try-Catch block.
Here is my code:
Public Class frmMistyRiver
Dim cost As Decimal
Dim nights As Integer
Dim subtotal As Decimal
Dim subtotalDiscount As Decimal
Dim total As Decimal
Dim StateTax As Decimal
Const AAA As Double = 0.1
Const MILITARY As Double = 0.12
Const TAXES As Double = 0.075
Private Sub cboSite_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboSite.SelectedIndexChanged
ShowLabels()
End Sub
Private Sub txtNights_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNights.TextChanged
ShowLabels()
End Sub
Private Sub ShowLabels()
If cboSite.Text “” And txtNights.Text “” Then
lblSubtotal.Visible = True
lblTaxes.Visible = True
lblTotal.Visible = True
CalculateSubtotal()
Discount()
End If
End Sub
Private Sub CalculateSubtotal()
If cboSite.Text = “Tent Site” Then
If txtNights.Text “” Then
cost = 20
nights = Convert.ToInt32(txtNights.Text)
subtotal = cost * nights
End If
ElseIf cboSite.Text = “RV Site” Then
If txtNights.Text “” Then
cost = 35
nights = Convert.ToInt32(txtNights.Text)
subtotal = cost * nights
End If
ElseIf cboSite.Text = “Cabin Rental” Then
If txtNights.Text “” Then
cost = 55
nights = Convert.ToInt32(txtNights.Text)
subtotal = cost * nights
End If
End If
End Sub
Private Sub Discount()
If rdoAAA.Checked = True Then
subtotalDiscount = subtotal – (subtotal * Convert.ToDecimal(AAA))
ElseIf rdoMilitary.Checked = True Then
subtotalDiscount = subtotal – (subtotal * Convert.ToDecimal(MILITARY))
Else
subtotalDiscount = subtotal
End If
CalculateSubtotal()
Tax()
DisplayFinal()
End Sub
Private Sub Tax()
StateTax = subtotalDiscount * Convert.ToDecimal(TAXES)
total = subtotalDiscount + StateTax
End Sub
Private Sub DisplayFinal()
lblSub.Text = subtotalDiscount.ToString(“C”)
lblTax.Text = StateTax.ToString(“C”)
lblFinal.Text = total.ToString(“C”)
lblSub.Visible = True
lblTax.Visible = True
lblFinal.Visible = True
End Sub
Private Sub rdoAAA_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoAAA.CheckedChanged
Discount()
End Sub
Private Sub rdoMilitary_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoMilitary.CheckedChanged
Discount()
End Sub
End Class
All I need to know is how to insert that Try-Catch code somewhere in there for the number of days.

Both comments and pings are currently closed.

One Response to “Need Help With Visual Basic Homework, Try-catch?”

  1. Robert says:

    The idea of Try/Catch is to handle errors you can imagine might happen if people enter odd things. So wherever you have:
    nights = Convert.ToInt32(txtNights.Text)
    … make it …
    Try
    nights = Convert.ToInt32(txtNights.Text)
    Catch ex As Exception
    nights = 0
    ‘ Optional embellish
    ‘ End of optional embellish
    End Try
    … embellish as required with an error message.

Powered by WordPress | Designed by: free css template | Thanks to hostgator coupon and web hosting reviews