NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Validation...

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 05-11-2009, 11:47 PM THREAD STARTER               #1 (permalink)
Account Suspended
Join Date: May 2009
Posts: 5
Makati Law Firm is an unknown quantity at this point
 



Validation...


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 Eric; 05-12-2009 at 12:00 AM. Reason: placed within code tags, easier to read ;)
Makati Law Firm is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
$10 to Fix - AJAX JQuery Form Validation Ik Web Development Wanted 8 12-31-2008 03:32 PM
Data Validation script for forms Krazza Programming 3 04-07-2007 05:34 PM
javascript vs asp.net validation tzigone Web Design Discussion 0 01-21-2004 12:37 AM
Automatic Form Validation transio CODE 1 07-30-2003 09:55 AM

 
All times are GMT -7. The time now is 02:30 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger