Makati Law Firm
Account Closed
- Impact
- 0
I am having problem in this program all the calculations are right so no math problems however, I can't get the validation to work so whenever I enter a letter into my text box it will just try to calculate letters. I've tried Is numeric and it doesn't work. I've tried Try Catch and still doesn't work. Please help.

Code:
Option Strict On
Option Explicit On
Public Class Form1
'James Blakeman
'May 7, 2009
'Application takes all calculations of user's inputed data.
'Constants
Const dblMEALS As Double = 37
Const dblMIlES As Double = 0.27
Const dblPARKING As Double = 10
Const dblTAXI As Double = 20
Const dblLODGE As Double = 95
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
'Dim statements
Dim dblTotal As Double
Dim dblSaved As Double
Dim dblReimbursed As Double
Dim dblUnallowed As Double
dblTotal = CalcMeals() + CalcLodging() + CalcParkingFees() + CalcTaxiFees() _
+ CalcMileage() + CalcUnallowed() + CalcAirfare() + CalcRental() + CalcRegistration()
lblCustomerTotal.Text = FormatCurrency(dblTotal.ToString)
dblReimbursed = CalcTotalReimbursement()
lblAllowed.Text = FormatCurrency(dblReimbursed.ToString)
dblSaved = CalcSaved()
lblSaved.Text = FormatCurrency(dblSaved.ToString)
dblUnallowed = CalcUnallowed()
lblOverage.Text = FormatCurrency(dblUnallowed.ToString)
End Sub
Function CalcMeals() As Double
'Dim Statement
Dim dblTotalMeal As Double
If Double.TryParse(txtDaysTrip.Text, dblTotalMeal) Then
If Not txtDaysTrip.Text = String.Empty Then
If CDbl(txtDaysTrip.Text) < 1 Then
MessageBox.Show("Enter a value greater than zero.", "Error")
Else
dblTotalMeal = dblMEALS * CDbl(txtDaysTrip.Text)
End If
End If
Return (dblTotalMeal)
End If
End Function
Function CalcMileage() As Double
'Dim Statement
Dim dblTotalMiles As Double
If Double.TryParse(txtMiles.Text, dblTotalMiles) Then
If Not txtMiles.Text = String.Empty Then
If CDbl(txtMiles.Text) < 0 Then
MessageBox.Show("Enter a number that is not negative.", "Error")
Else
dblTotalMiles = dblMIlES * CDbl(txtMiles.Text)
End If
End If
End If
Return (dblTotalMiles)
End Function
Function CalcParkingFees() As Double
'Dim Statement
Dim dblParkingTotal As Double
If Double.TryParse(txtParking.Text, dblParkingTotal) Then
If Not txtParking.Text = String.Empty Then
If CDbl(txtParking.Text) < 0 Then
MessageBox.Show("Enter a number that is not negative.", "Error")
Else
dblParkingTotal = dblPARKING * CDbl(txtDaysTrip.Text)
End If
End If
End If
Return (dblParkingTotal)
End Function
Function CalcTaxiFees() As Double
'Dim Statement
Dim dblTaxiTotal As Double
If Double.TryParse(txtTaxi.Text, dblTaxiTotal) Then
If Not txtTaxi.Text = String.Empty Then
If CDbl(txtTaxi.Text) < 0 Then
MessageBox.Show("Enter a number that is not negative.", "Error")
Else
dblTaxiTotal = dblTAXI * CDbl(txtDaysTrip.Text)
End If
End If
End If
Return (dblTaxiTotal)
End Function
Function CalcLodging() As Double
'Dim Statement
Dim dblLodgeTotal As Double
If Double.TryParse(txtLodge.Text, dblLodgeTotal) Then
If Not txtLodge.Text = String.Empty Then
If CDbl(txtLodge.Text) < 0 Then
MessageBox.Show("Enter a number that is not negative.", "Error")
Else
dblLodgeTotal = dblLODGE * CDbl(txtDaysTrip.Text)
End If
End If
End If
Return (dblLodgeTotal)
End Function
Function CalcAirfare() As Double
Dim dblAirfare As Double
If Double.TryParse(txtAirfare.Text, dblAirfare) Then
If Not txtAirfare.Text = String.Empty Then
If CDbl(txtAirfare.Text) < 0 Then
MessageBox.Show("Enter a number that is not negative.", "Error")
Else
dblAirfare = CDbl(txtAirfare.Text)
End If
End If
End If
End Function
Function CalcRental() As Double
Dim dblRental As Double
If Double.TryParse(txtRental.Text, dblRental) Then
If Not txtRental.Text = String.Empty Then
If CDbl(txtRental.Text) < 0 Then
MessageBox.Show("Enter a number that is not negative.", "Error")
Else
dblRental = CDbl(txtRental.Text)
End If
End If
End If
Return (dblRental)
End Function
Function CalcRegistration() As Double
Dim dblRegistration As Double
If Double.TryParse(txtRegistration.Text, dblRegistration) Then
If Not txtRegistration.Text = String.Empty Then
If CDbl(txtRegistration.Text) < 0 Then
MessageBox.Show("Enter a number that is not negative.", "Error")
Else
dblRegistration = CDbl(txtRegistration.Text)
End If
End If
End If
Return (dblRegistration)
End Function
Function CalcTotalReimbursement() As Double
'Dim Statement
Dim dblTotalReimbursed As Double
dblTotalReimbursed = CalcLodging() + CalcMeals() + CalcMileage() + CalcParkingFees() _
+ CalcTaxiFees() + CalcAirfare() + CalcRental() + CalcRegistration()
Return (dblTotalReimbursed)
End Function
Function CalcSaved() As Double
'Dim Statement
Dim dblCustomerSaved1 As Double
Dim dblCustomerSaved2 As Double
Dim dblCustomerSaved3 As Double
Dim dblSavedTotal As Double
If Not txtLodge.Text = String.Empty Then
If CDbl(txtLodge.Text) < dblLODGE Then
dblCustomerSaved1 = CalcLodging() - (CDbl(txtLodge.Text) * CDbl(txtDaysTrip.Text))
End If
End If
If Not txtParking.Text = String.Empty Then
If CDbl(txtParking.Text) < dblPARKING Then
dblCustomerSaved2 = CalcParkingFees() - (CDbl(txtParking.Text) * CDbl(txtDaysTrip.Text))
End If
End If
If Not txtTaxi.Text = String.Empty Then
If CDbl(txtTaxi.Text) < dblTAXI Then
dblCustomerSaved3 = CalcTaxiFees() - (CDbl(txtTaxi.Text) * CDbl(txtDaysTrip.Text))
End If
End If
dblSavedTotal = (dblCustomerSaved1 + dblCustomerSaved2) + dblCustomerSaved3
Return (dblSavedTotal)
End Function
Function CalcUnallowed() As Double
Dim dblCustomerTotal1 As Double
Dim dblCustomerTotal2 As Double
Dim dblCustomerTotal3 As Double
Dim dblCompleteTotal As Double
If Not txtLodge.Text = String.Empty Then
If CDbl(txtLodge.Text) > dblLODGE Then
dblCustomerTotal1 = (CDbl(txtLodge.Text) * CDbl(txtDaysTrip.Text)) - CalcLodging()
End If
End If
If Not txtParking.Text = String.Empty Then
If CDbl(txtParking.Text) > dblPARKING Then
dblCustomerTotal2 = (CDbl(txtParking.Text) * CDbl(txtDaysTrip.Text)) - CalcParkingFees()
End If
End If
If Not txtTaxi.Text = String.Empty Then
If CDbl(txtTaxi.Text) > dblTAXI Then
dblCustomerTotal3 = (CDbl(txtTaxi.Text) * CDbl(txtDaysTrip.Text)) - CalcTaxiFees()
End If
End If
dblCompleteTotal = (dblCustomerTotal1 + dblCustomerTotal2) + dblCustomerTotal3
Return (dblCompleteTotal)
End Function
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Terminates Program
Me.Close()
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
'Clear's Form
txtAirfare.Text = String.Empty
txtDaysTrip.Text = String.Empty
txtLodge.Text = String.Empty
txtMiles.Text = String.Empty
txtParking.Text = String.Empty
txtRegistration.Text = String.Empty
txtRental.Text = String.Empty
txtTaxi.Text = String.Empty
lblCustomerTotal.Text = String.Empty
lblOverage.Text = String.Empty
lblAllowed.Text = String.Empty
lblSaved.Text = String.Empty
'Returns Focus
txtDaysTrip.Focus()
End Sub
End Class
Last edited by a moderator:







