Validation-VBForums
Results 1 to 2 of 2

Thread: Validation

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    8

    Validation

    I messed up somewhere with my variables and now when I do any data validation the program crashes and will not catch the error, The number of passengers has to be a number between 1 and 10 here is my code



    Option Strict On
    Public Class Form1

    Private Sub DepartKenaiRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles DepartKenaiRadioButton.CheckedChanged
    'disable and enable radio buttons
    If DepartKenaiRadioButton.Checked = True Then
    DestKenaiRadioButton.Enabled = False
    DestSewardRadioButton.Enabled = True
    DestHomerRadioButton.Enabled = True
    DestNinilchikRadioButton.Enabled = True
    End If
    End Sub

    Private Sub DepartSewardRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles DepartSewardRadioButton.CheckedChanged
    'disable and enable radio buttons
    If DepartSewardRadioButton.Checked = True Then
    DestSewardRadioButton.Enabled = False
    DestKenaiRadioButton.Enabled = True
    DestHomerRadioButton.Enabled = True
    DestNinilchikRadioButton.Enabled = True
    End If
    End Sub

    Private Sub DepartHomerRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles DepartHomerRadioButton.CheckedChanged
    'disable and enable radio buttons
    If DepartHomerRadioButton.Checked = True Then
    DestHomerRadioButton.Enabled = False
    DestKenaiRadioButton.Enabled = True
    DestSewardRadioButton.Enabled = True
    DestNinilchikRadioButton.Enabled = True
    End If
    End Sub

    Private Sub DepartNinilchikRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles DepartNinilchikRadioButton.CheckedChanged
    'disable and enable radio buttons
    If DepartNinilchikRadioButton.Checked = True Then
    DestNinilchikRadioButton.Enabled = False
    DestKenaiRadioButton.Enabled = True
    DestSewardRadioButton.Enabled = True
    DestHomerRadioButton.Enabled = True
    End If
    End Sub

    Private Sub QuoteButton_Click(sender As System.Object, e As System.EventArgs) Handles QuoteButton.Click
    'declare variables
    Dim NumPassengersInteger As Integer
    Dim QuotePassengerCostDecimal As Decimal
    Dim PlaneTypeString As String
    Dim TicketCostDecimal As Decimal

    'Declare constants
    Const ONE_KENAI_TO_SEWARD_DECIMAL As Decimal = 180
    Const ONE_KENAI_TO_NINILCHIK_DECIMAL As Decimal = 150
    Const ONE_KENAI_TO_HOMER_DECIMAL As Decimal = 200
    Const ONE_SEWARD_TO_NINILCHIK_DECIMAL As Decimal = 225
    Const ONE_SEWARD_TO_HOMER_DECIMAL As Decimal = 190
    Const ONE_NINILCHIK_TO_HOMER_DECIMAL As Decimal = 170
    Const ROUND_KENAI_TO_SEWARD_DECIMAL As Decimal = 300
    Const ROUND_KENAI_TO_NINILCHIK_DECIMAL As Decimal = 250
    Const ROUND_KENAI_TO_HOMER_DECIMAL As Decimal = 335
    Const ROUND_SEWARD_TO_NINILCHIK_DECIMAL As Decimal = 375
    Const ROUND_SEWARD_TO_HOMER_DECIMAL As Decimal = 315
    Const ROUND_NINILCHIK_TO_HOMER_DECIMAL As Decimal = 285

    ''Validation
    'Try

    'get num passengers
    NumPassengersInteger = Integer.Parse(NumPassengersTextBox.Text)

    'Get plane type
    If NumPassengersInteger = 1 Then
    PlaneTypeString = "Piper Cub"
    End If

    If NumPassengersInteger = 2 Or NumPassengersInteger = 3 Then
    PlaneTypeString = "Cessna 170"
    End If

    If NumPassengersInteger = 4 Or NumPassengersInteger = 5 Then
    PlaneTypeString = "Cessna 206"
    End If

    If NumPassengersInteger > 5 Or NumPassengersInteger < 11 Then
    PlaneTypeString = "DeHavilland Beaver"
    End If

    AircraftTextBox.Text = PlaneTypeString


    'find ticket cost
    If DepartKenaiRadioButton.Checked = True And DestSewardRadioButton.Checked = True Then
    TicketCostDecimal = ONE_KENAI_TO_SEWARD_DECIMAL
    End If

    If DepartKenaiRadioButton.Checked = True And DestNinilchikRadioButton.Checked = True Then
    TicketCostDecimal = ONE_KENAI_TO_NINILCHIK_DECIMAL
    End If

    If DepartKenaiRadioButton.Checked = True And DestHomerRadioButton.Checked = True Then
    TicketCostDecimal = ONE_KENAI_TO_HOMER_DECIMAL
    End If

    If DepartSewardRadioButton.Checked = True And DestNinilchikRadioButton.Checked = True Then
    TicketCostDecimal = ONE_SEWARD_TO_NINILCHIK_DECIMAL
    End If

    If DepartSewardRadioButton.Checked = True And DestHomerRadioButton.Checked = True Then
    TicketCostDecimal = ONE_SEWARD_TO_HOMER_DECIMAL
    End If

    If DepartNinilchikRadioButton.Checked = True And DestHomerRadioButton.Checked = True Then
    TicketCostDecimal = ONE_NINILCHIK_TO_HOMER_DECIMAL
    End If

    If DepartKenaiRadioButton.Checked = True And DestSewardRadioButton.Checked = True And RoundTripCheckBox.Checked = True Then
    TicketCostDecimal = ROUND_KENAI_TO_SEWARD_DECIMAL
    End If

    If DepartKenaiRadioButton.Checked = True And DestNinilchikRadioButton.Checked = True And RoundTripCheckBox.Checked = True Then
    TicketCostDecimal = ROUND_KENAI_TO_NINILCHIK_DECIMAL
    End If

    If DepartKenaiRadioButton.Checked = True And DestHomerRadioButton.Checked = True And RoundTripCheckBox.Checked = True Then
    TicketCostDecimal = ROUND_KENAI_TO_HOMER_DECIMAL
    End If

    If DepartSewardRadioButton.Checked = True And DestNinilchikRadioButton.Checked = True And RoundTripCheckBox.Checked = True Then
    TicketCostDecimal = ROUND_SEWARD_TO_NINILCHIK_DECIMAL
    End If

    If DepartSewardRadioButton.Checked = True And DestHomerRadioButton.Checked = True And RoundTripCheckBox.Checked = True Then
    TicketCostDecimal = ROUND_SEWARD_TO_HOMER_DECIMAL
    End If

    If DepartNinilchikRadioButton.Checked = True And DestHomerRadioButton.Checked = True And RoundTripCheckBox.Checked = True Then
    TicketCostDecimal = ROUND_NINILCHIK_TO_HOMER_DECIMAL
    End If

    'determind quote
    QuotePassengerCostDecimal = NumPassengersInteger * TicketCostDecimal
    RateTextBox.Text = CStr(QuotePassengerCostDecimal)

    'Catch FormatNumPassengerException As FormatException
    ' MessageBox.Show("Please enter Number of passengers as a positive number format", "Error", MessageBoxButtons.OK)
    'End Try

    End Sub

    Private Sub ClearButton_Click(sender As System.Object, e As System.EventArgs) Handles ClearButton.Click
    'reset to defaults
    DepartKenaiRadioButton.Enabled = True
    DepartKenaiRadioButton.Checked = True

    DestHomerRadioButton.Checked = False
    DestKenaiRadioButton.Checked = False
    DestNinilchikRadioButton.Checked = False
    DestSewardRadioButton.Checked = False
    RoundTripCheckBox.Checked = False
    NumPassengersTextBox.Clear()
    AircraftTextBox.Clear()
    RateTextBox.Clear()

    'focus to depart group box
    DepartGroupBox.Focus()

    End Sub

    Private Sub CloseButton_Click(sender As System.Object, e As System.EventArgs) Handles CloseButton.Click
    Me.Close()
    End Sub
    End Class

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,002

    Re: Validation

    Not a deployment question.

    Try asking here: http://www.vbforums.com/forumdisplay.php?f=25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.