Results 1 to 3 of 3

Thread: [2005] System.ArgumentNullException occurred in System.dll

  1. #1

    Thread Starter
    Member mjbrown20's Avatar
    Join Date
    Nov 2006
    Posts
    33

    Question [2005] System.ArgumentNullException occurred in System.dll

    **This is homework, but I am not seeking help on the assignment itself**
    I am get the following error in the immediate window when I run the project.

    "A first chance exception of type System.ArgumentNullException occurred in System.dll" (there is no line number)

    VB Code:
    1. Imports System.Text.RegularExpressions
    2. Public Class ReservationsForm
    3.     Inherits System.Windows.Forms.Form
    4.     Private Shared anInstance As ReservationsForm
    5.     Dim checkinDate As Date
    6.     Dim checkoutdate As Date
    7.     Dim phoneString As String
    8.     Dim stateString As String
    9.     Dim zipString As String
    10.     Dim cardString As String
    11.     Private Sub lnameTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles lnameTextBox.Validating
    12.         'Validate the Last Name textbox.
    13.         With Me
    14.             'Clear the errorprovider.
    15.             ErrorProvider1.Clear()
    16.             'Ensure Last Name is not blank, and is not Numeric.
    17.             If Not Regex.IsMatch(lnameTextBox.Text, "^[a-zA-Z'`-´\s]{1,40}$") Then
    18.                 ErrorProvider1.SetError(lnameTextBox, "Please enter a Last Name. Last Name can not contain numbers.")
    19.                 lnameTextBox.SelectAll()
    20.                 lnameTextBox.Focus()
    21.             Else
    22.                 'Ensure the error is Nothing and Clear the error provider.
    23.                 With ErrorProvider1
    24.                     .SetError(lnameTextBox, Nothing)
    25.                     .Clear()
    26.                 End With
    27.             End If
    28.         End With
    29.     End Sub
    30.     Private Sub fnameTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles fnameTextBox.Validating
    31.         'Validate the First Name textbox.
    32.         With Me
    33.             'Clear the errorprovider.
    34.             ErrorProvider1.Clear()
    35.             'Ensure First Name is not blank, and is not Numeric.
    36.             If Not Regex.IsMatch(fnameTextBox.Text, "^[a-zA-Z'`-´\s]{1,40}$") Then
    37.                 ErrorProvider1.SetError(fnameTextBox, "Please enter a first Name. First Name can not contain numbers.")
    38.                 fnameTextBox.SelectAll()
    39.                 fnameTextBox.Focus()
    40.             Else
    41.                 'Ensure the error is Nothing and Clear the error provider.
    42.                 With ErrorProvider1
    43.                     .SetError(fnameTextBox, Nothing)
    44.                     .Clear()
    45.                 End With
    46.             End If
    47.         End With
    48.     End Sub
    49.     Private Sub addressTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles addressTextBox.Validating
    50.         'Validate the address textbox.
    51.         With Me
    52.             'Clear the errorprovider.
    53.             ErrorProvider1.Clear()
    54.             'Ensure address is not blank.
    55.             If addressTextBox.Text = "" Then
    56.                 ErrorProvider1.SetError(addressTextBox, "Please enter an address.")
    57.                 addressTextBox.SelectAll()
    58.                 addressTextBox.Focus()
    59.             Else
    60.                 'Ensure the error is Nothing and Clear the error provider.
    61.                 With ErrorProvider1
    62.                     .SetError(addressTextBox, Nothing)
    63.                     .Clear()
    64.                 End With
    65.             End If
    66.         End With
    67.     End Sub
    68.     Private Sub cityTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cityTextBox.Validating
    69.         'Validate the City textbox.
    70.         With Me
    71.             'Clear the errorprovider.
    72.             ErrorProvider1.Clear()
    73.             'Ensure City is not blank, and is not Numeric.
    74.             If Not Regex.IsMatch(cityTextBox.Text, "^[a-zA-Z'`-´\s]{1,40}$") Then
    75.                 ErrorProvider1.SetError(cityTextBox, "Please enter a City. City can not contain numbers.")
    76.                 cityTextBox.SelectAll()
    77.                 cityTextBox.Focus()
    78.             Else
    79.                 'Ensure the error is Nothing and Clear the error provider.
    80.                 With ErrorProvider1
    81.                     .SetError(cityTextBox, Nothing)
    82.                     .Clear()
    83.                 End With
    84.             End If
    85.         End With
    86.     End Sub
    87.     Private Sub stateTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles stateTextBox.Validating
    88.         'Validate the State textbox.
    89.         'Ensure the State is upper case.
    90.         stateString = stateTextBox.Text.ToUpper
    91.         stateTextBox.Text = stateString
    92.         With Me
    93.             'Clear the errorprovider.
    94.             ErrorProvider1.Clear()
    95.             'Ensure State is not blank, and is not Numeric.
    96.             If Len(stateString) <> 2 OrElse Not Regex.IsMatch(stateString, "^[A-Z]{1,40}$") Then
    97.                 ErrorProvider1.SetError(stateTextBox, "Please enter a State. State can not contain numbers.")
    98.                 stateTextBox.SelectAll()
    99.                 stateTextBox.Focus()
    100.             Else
    101.                 'Ensure the error is Nothing and Clear the error provider.
    102.                 With ErrorProvider1
    103.                     .SetError(stateTextBox, Nothing)
    104.                     .Clear()
    105.                 End With
    106.             End If
    107.         End With
    108.     End Sub
    109.     Private Sub phoneTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles phoneTextBox.Validating
    110.         'Validate the Phone textbox.
    111.         'Mask set to numeric, no need to check for alpha characters.
    112.         phoneString = phoneTextBox.Text
    113.         With Me
    114.             'Clear the errorprovider.
    115.             ErrorProvider1.Clear()
    116.             'Ensure Phone number is not blank, and contains all 10 digits.
    117.             If Len(phoneString) < 13 Then
    118.                 ErrorProvider1.SetError(phoneTextBox, "Phone number must contain 10 digits.")
    119.                 phoneTextBox.SelectAll()
    120.                 phoneTextBox.Focus()
    121.             Else
    122.                 'Ensure the error is Nothing and Clear the error provider.
    123.                 With ErrorProvider1
    124.                     .SetError(phoneTextBox, Nothing)
    125.                     .Clear()
    126.                End With
    127.             End If
    128.         End With
    129.     End Sub
    130.    Private Sub zipTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles zipTextBox.Validating
    131.         'Validate the zip code.
    132.         'Mask set to numeric, no need to check for alpha characters.
    133.         zipString = zipTextBox.Text
    134.         With Me
    135.             'Clear the errorprovider.
    136.             ErrorProvider1.Clear()
    137.             'Ensure Zip Code is numeric and contains all 5 digits.
    138.             If Not IsNumeric(zipTextBox.Text) OrElse Not Len(zipString) = 5 Then
    139.                 ErrorProvider1.SetError(zipTextBox, "Zip Code must contain 5 digits.")
    140.                 zipTextBox.SelectAll()
    141.                 zipTextBox.Focus()
    142.             Else
    143.                 'Ensure the error is Nothing and Clear the error provider.
    144.                 With ErrorProvider1
    145.                     .SetError(zipTextBox, Nothing)
    146.                     .Clear()
    147.                End With
    148.             End If
    149.         End With
    150.     End Sub
    151.     Private Sub checkInDateTimePicker_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles checkInDateTimePicker.Validating
    152.         'Validate the check in date.
    153.         With Me
    154.             'Clear the errorprovider.
    155.             ErrorProvider1.Clear()
    156.             checkinDate = .checkInDateTimePicker.Value
    157.             If checkinDate < Date.Now.Date Then
    158.                 ErrorProvider1.SetError(checkInDateTimePicker, "Check in date can not be less than todays date.")
    159.                 .checkInDateTimePicker.Focus()
    160.             Else
    161.                 'Ensure the error is Nothing and Clear the error provider.
    162.                 With ErrorProvider1
    163.                     .SetError(checkInDateTimePicker, Nothing)
    164.                     .Clear()
    165.                 End With
    166.             End If
    167.         End With
    168.     End Sub
    169.     Private Sub checkOutDateTimePicker_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles checkOutDateTimePicker.Validating
    170.         'Validate the check out date.
    171.         With Me
    172.             'Clear the errorprovider.
    173.             ErrorProvider1.Clear()
    174.             checkoutdate = .checkOutDateTimePicker.Value
    175.             If Not checkoutdate > checkinDate Then
    176.                 ErrorProvider1.SetError(checkOutDateTimePicker, "Check out date must be greater than check in date.")
    177.                 .checkOutDateTimePicker.Focus()
    178.             Else
    179.                 'Ensure the error is Nothing and Clear the error provider.
    180.                 With ErrorProvider1
    181.                     .SetError(checkOutDateTimePicker, Nothing)
    182.                     .Clear()
    183.                 End With
    184.             End If
    185.         End With
    186.     End Sub
    187.     Private Sub cardTypeComboBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cardTypeComboBox.Validating
    188.         'Validate Card Type.
    189.         With Me
    190.             'Clear the errorprovider.
    191.             ErrorProvider1.Clear()
    192.             If .cardTypeComboBox.SelectedIndex = -1 Then
    193.                 ErrorProvider1.SetError(cardTypeComboBox, "Please select a Card Type.")
    194.                 .cardTypeComboBox.Focus()
    195.             Else
    196.                 'Ensure the error is Nothing and Clear the error provider.
    197.                 With ErrorProvider1
    198.                     .SetError(cardTypeComboBox, Nothing)
    199.                     .Clear()
    200.                 End With
    201.             End If
    202.         End With
    203.     End Sub
    204.       End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] System.ArgumentNullException occurred in System.dll

    You don't have to worry about first chance exceptions. The debugger will notify you every time an exception is thrown. That's a first chance exception, because it's the first chance to catch it. If that exception is caught and the exceptional situation handled then execution continues. If the exception is not caught in code then the debugger is offered a second chance to catch the exception, at which point it shows you the unhandled exception dialogue. In your case, that exception is being thrown and caught within the Framework itself. You're notified that it occurred but you don't have to worry about it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member mjbrown20's Avatar
    Join Date
    Nov 2006
    Posts
    33

    Re: [2005] System.ArgumentNullException occurred in System.dll

    Thank you jmcilhinney.

Posting Permissions

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



Click Here to Expand Forum to Full Width