instance error on a control

  • Thread starter Thread starter Bruce
  • Start date Start date
B

Bruce

I get this error on a line that references any control in
the form_load sub:

An unhandled exception of
type 'System.NullReferenceException' occurred in
BC785dProg1.exe

Additional information: Object reference not set to an
instance of an object.

This program was working error free until this happened.
Now, if I remove the offending lines from the form_load
sub, the form appears but there are no controls on it.
Any ideas on what I might have done to cause this?
 
Hello,

Bruce said:
I get this error on a line that references any control in
the form_load sub:

An unhandled exception of
type 'System.NullReferenceException' occurred in
BC785dProg1.exe

Additional information: Object reference not set to an
instance of an object.

This program was working error free until this happened.
Now, if I remove the offending lines from the form_load
sub, the form appears but there are no controls on it.
Any ideas on what I might have done to cause this?

Please post the lines of code.

HTH,
Herfried K. Wagner
 
-----Original Message-----
Hello,



Please post the lines of code.

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


.
Here's tthe code. Thanks for having a look. Bruce

Private Sub frmBC785d_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
sCrLf = Chr(13) & Chr(10)
moRS232 = New Rs232()
Try
'// Setup parameters
With moRS232
.Port = 1
.BaudRate = 19200
.DataBit = 8
.StopBit = Rs232.DataStopBit.StopBit_1
.Parity = Rs232.DataParity.Parity_None
.Timeout = 80
.WorkingMode = 0
End With
'// Initializes port
moRS232.Open()
Catch Ex As Exception
MessageBox.Show(Ex.Message, "Connection
Error", MessageBoxButtons.OK)
Exit Sub
Finally
rbAll.Checked = True 'ERROR LINE
End Try
End Sub
 
Hello,


Delete the obj and bin directories (be careful!) and try again.
rbAll.Checked = True 'ERROR LINE

What is rbAll? Can you post the contents of "Sub InitializeComponent"?

Regards,
Herfried K. Wagner
 
-----Original Message-----
Hello,



Delete the obj and bin directories (be careful!) and try again.

What is rbAll? Can you post the contents of "Sub InitializeComponent"?

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.txtPrgm = New System.Windows.Forms.TextBox()
Me.lblProg = New System.Windows.Forms.Label()
Me.MainMenu1 = New System.Windows.Forms.MainMenu()
Me.MenuItem1 = New System.Windows.Forms.MenuItem()
Me.mnuLoadFile = New System.Windows.Forms.MenuItem
()
Me.mnuReadRadio = New
System.Windows.Forms.MenuItem()
Me.mnuSaveFile = New System.Windows.Forms.MenuItem
()
Me.mnuWriteRadio = New
System.Windows.Forms.MenuItem()
Me.mnuClrLockouts = New
System.Windows.Forms.MenuItem()
Me.MenuItem7 = New System.Windows.Forms.MenuItem()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.rbAll = New System.Windows.Forms.RadioButton()
Me.rb10 = New System.Windows.Forms.RadioButton()
Me.rb9 = New System.Windows.Forms.RadioButton()
Me.rb8 = New System.Windows.Forms.RadioButton()
Me.rb7 = New System.Windows.Forms.RadioButton()
Me.rb6 = New System.Windows.Forms.RadioButton()
Me.rb5 = New System.Windows.Forms.RadioButton()
Me.rb4 = New System.Windows.Forms.RadioButton()
Me.rb3 = New System.Windows.Forms.RadioButton()
Me.rb2 = New System.Windows.Forms.RadioButton()
Me.rb1 = New System.Windows.Forms.RadioButton()
Me.rbFile = New System.Windows.Forms.RadioButton()
Me.rbRadio = New System.Windows.Forms.RadioButton
()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'txtPrgm
'
Me.txtPrgm.Location = New System.Drawing.Point(8,
48)
Me.txtPrgm.Multiline = True
Me.txtPrgm.Name = "txtPrgm"
Me.txtPrgm.ScrollBars =
System.Windows.Forms.ScrollBars.Vertical
Me.txtPrgm.Size = New System.Drawing.Size(512,
160)
Me.txtPrgm.TabIndex = 0
Me.txtPrgm.Text = ""
Me.txtPrgm.WordWrap = False
'
'lblProg
'
Me.lblProg.Location = New System.Drawing.Point
(16, 32)
Me.lblProg.Name = "lblProg"
Me.lblProg.Size = New System.Drawing.Size(96, 16)
Me.lblProg.TabIndex = 1
Me.lblProg.Text = "Scanner Program:"
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New
System.Windows.Forms.MenuItem() {Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New
System.Windows.Forms.MenuItem() {Me.mnuLoadFile,
Me.mnuReadRadio, Me.mnuSaveFile, Me.mnuWriteRadio,
Me.mnuClrLockouts, Me.MenuItem7})
Me.MenuItem1.Text = "File"
'
'mnuLoadFile
'
Me.mnuLoadFile.Index = 0
Me.mnuLoadFile.Text = "Load Program from &File"
'
'mnuReadRadio
'
Me.mnuReadRadio.Index = 1
Me.mnuReadRadio.Text = "Load Program from &Radio"
'
'mnuSaveFile
'
Me.mnuSaveFile.Index = 2
Me.mnuSaveFile.Text = "&Save Program to File"
'
'mnuWriteRadio
'
Me.mnuWriteRadio.Index = 3
Me.mnuWriteRadio.Text = "Write &TextBox Contents
to Radio"
'
'mnuClrLockouts
'
Me.mnuClrLockouts.Index = 4
Me.mnuClrLockouts.Text = "Clear Lockouts in
Selected Bank"
'
'MenuItem7
'
Me.MenuItem7.Index = 5
Me.MenuItem7.Text = "Exit"
'
'GroupBox1
'
Me.GroupBox1.Controls.AddRange(New
System.Windows.Forms.Control() {Me.rbAll, Me.rb10,
Me.rb9, Me.rb8, Me.rb7, Me.rb6, Me.rb5, Me.rb4, Me.rb3,
Me.rb2, Me.rb1})
Me.GroupBox1.Location = New System.Drawing.Point
(104, 0)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(248,
48)
Me.GroupBox1.TabIndex = 2
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Bank #"
'
'rbAll
'
Me.rbAll.Checked = True
Me.rbAll.Location = New System.Drawing.Point(208,
24)
Me.rbAll.Name = "rbAll"
Me.rbAll.Size = New System.Drawing.Size(48, 24)
Me.rbAll.TabIndex = 10
Me.rbAll.TabStop = True
Me.rbAll.Text = "ALL"
'
'rb10
'
Me.rb10.Location = New System.Drawing.Point(176,
24)
Me.rb10.Name = "rb10"
Me.rb10.Size = New System.Drawing.Size(40, 24)
Me.rb10.TabIndex = 9
Me.rb10.Text = "10"
'
'rb9
'
Me.rb9.Location = New System.Drawing.Point(144,
24)
Me.rb9.Name = "rb9"
Me.rb9.Size = New System.Drawing.Size(32, 24)
Me.rb9.TabIndex = 8
Me.rb9.Text = "9"
'
'rb8
'
Me.rb8.Location = New System.Drawing.Point(112,
24)
Me.rb8.Name = "rb8"
Me.rb8.Size = New System.Drawing.Size(32, 24)
Me.rb8.TabIndex = 7
Me.rb8.Text = "8"
'
'rb7
'
Me.rb7.Location = New System.Drawing.Point(80, 24)
Me.rb7.Name = "rb7"
Me.rb7.Size = New System.Drawing.Size(32, 24)
Me.rb7.TabIndex = 6
Me.rb7.Text = "7"
'
'rb6
'
Me.rb6.Location = New System.Drawing.Point(48, 24)
Me.rb6.Name = "rb6"
Me.rb6.Size = New System.Drawing.Size(32, 24)
Me.rb6.TabIndex = 5
Me.rb6.Text = "6"
'
'rb5
'
Me.rb5.Location = New System.Drawing.Point(176, 8)
Me.rb5.Name = "rb5"
Me.rb5.Size = New System.Drawing.Size(32, 16)
Me.rb5.TabIndex = 4
Me.rb5.Text = "5"
'
'rb4
'
Me.rb4.Location = New System.Drawing.Point(144, 8)
Me.rb4.Name = "rb4"
Me.rb4.Size = New System.Drawing.Size(24, 16)
Me.rb4.TabIndex = 3
Me.rb4.Text = "4"
'
'rb3
'
Me.rb3.Location = New System.Drawing.Point(112, 8)
Me.rb3.Name = "rb3"
Me.rb3.Size = New System.Drawing.Size(32, 16)
Me.rb3.TabIndex = 2
Me.rb3.Text = "3"
'
'rb2
'
Me.rb2.Location = New System.Drawing.Point(80, 8)
Me.rb2.Name = "rb2"
Me.rb2.Size = New System.Drawing.Size(32, 16)
Me.rb2.TabIndex = 1
Me.rb2.Text = "2"
'
'rb1
'
Me.rb1.Location = New System.Drawing.Point(48, 8)
Me.rb1.Name = "rb1"
Me.rb1.Size = New System.Drawing.Size(24, 16)
Me.rb1.TabIndex = 0
Me.rb1.Text = "1"
'
'rbFile
'
Me.rbFile.Location = New System.Drawing.Point(16,
8)
Me.rbFile.Name = "rbFile"
Me.rbFile.Size = New System.Drawing.Size(48, 24)
Me.rbFile.TabIndex = 3
Me.rbFile.Text = "File"
'
'rbRadio
'
Me.rbRadio.Location = New System.Drawing.Point
(56, 8)
Me.rbRadio.Name = "rbRadio"
Me.rbRadio.Size = New System.Drawing.Size(56, 24)
Me.rbRadio.TabIndex = 4
Me.rbRadio.Text = "Radio"
'
'frmBC785d
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5,
13)
Me.ClientSize = New System.Drawing.Size(528, 273)
Me.Controls.AddRange(New
System.Windows.Forms.Control() {Me.rbRadio, Me.rbFile,
Me.GroupBox1, Me.lblProg, Me.txtPrgm})
Me.Menu = Me.MainMenu1
Me.Name = "frmBC785d"
Me.Text = "BC785d Controller"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub
 
-----Original Message-----
Hello,



Delete the obj and bin directories (be careful!) and try again.

What is rbAll? Can you post the contents of "Sub InitializeComponent"?

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


.

Deleting the obj and bin directories made no difference.
Bruce
 
Hello,

[Sourcecode]

Mhmmm. The code looks OK.

Regards,
Herfried K. Wagner
 
Back
Top