NullReferenceException Woe's

Carta

Member
Joined
Apr 11, 2008
Messages
9
Programming Experience
1-3
Hey Guys, I am currently studying computing at university and I am in my final year. For one of my modules I have been set the task of creating a message board control system to work in an airport. I need to create a custom user control to act as a generic message board, so that board can become any type of board at the push of a button. Say It needs to be an arrivals board, click arrivals then board one and that control will say Arrivals and show plane arrivals. I need to have 3 generic boards that can become arrivals, departures and a random gate. I am now struggling with some of the code.

Another specification of this program, is that a message typed into a text box from the control panel of the program can be sent to any board. Now I need some error handling as length of this message must be shorter then 30 chars, so this is the code for one of the controls, (basic at the moment)
VB.NET:
Inherits System.Windows.Forms.UserControl
    Private errorcode As Integer
    Private in_mess As New String("Insert Message")




#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl1 overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents GB1 As System.Windows.Forms.GroupBox
    Friend WithEvents LB1 As System.Windows.Forms.Label
    Friend WithEvents LB2 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GB1 = New System.Windows.Forms.GroupBox
        Me.LB2 = New System.Windows.Forms.Label
        Me.LB1 = New System.Windows.Forms.Label
        Me.GB1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GB1
        '
        Me.GB1.Controls.Add(Me.LB2)
        Me.GB1.Controls.Add(Me.LB1)
        Me.GB1.Location = New System.Drawing.Point(0, 0)
        Me.GB1.Name = "GB1"
        Me.GB1.Size = New System.Drawing.Size(272, 152)
        Me.GB1.TabIndex = 0
        Me.GB1.TabStop = False
        '
        'LB2
        '
        Me.LB2.Location = New System.Drawing.Point(16, 120)
        Me.LB2.Name = "LB2"
        Me.LB2.Size = New System.Drawing.Size(216, 24)
        Me.LB2.TabIndex = 1
        '
        'LB1
        '
        Me.LB1.Location = New System.Drawing.Point(24, 16)
        Me.LB1.Name = "LB1"
        Me.LB1.Size = New System.Drawing.Size(224, 40)
        Me.LB1.TabIndex = 0
        '
        'UserControl1
        '
        Me.Controls.Add(Me.GB1)
        Me.Name = "UserControl1"
        Me.Size = New System.Drawing.Size(272, 152)
        Me.GB1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Public Property errornum() As Integer
        Get
            Return errorcode
        End Get
        Set(ByVal Value As Integer)

        End Set
    End Property

    Public Property mess1() As String
        Get
            Return in_mess
        End Get
        Set(ByVal Value As String)
            in_mess = Value
            If in_mess.Length > 20 Then

                errorcode = 1
            Else
                errorcode = 0
            End If
            LB2.Text = in_mess
        End Set
    End Property

    Public Property messname() As String
        Get

        End Get
        Set(ByVal Value As String)
            LB1.Text = Value
        End Set
    End Property
When I come to compile it, I get a unhandled exception error
An unhandled exception of type 'System.NullReferenceException' occurred in mycustomcontrol.dll

Additional information: Object reference not set to an instance of an object
Highlighting if in_mess.length is > 20 then

Any Ideas?
 
Last edited by a moderator:
many appologies, first post there. Sorted that problem out anyway. Made it a write only property and it works. Thanks
Dan
 
Back
Top