System.NullReferenceException in vb.net CF

Wolfgard
01-05-2005, 09:35 AM
Can somebody help me out? I'm currently learning how to write .NET Compact Framework in VB.NET but this error keeps coming out when I try to retrieve data from textboxes in another form (as a dialog box): System.NullReferenceException

Here's the code for the parent form:

Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents btnShowDialog As System.Windows.Forms.Button
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

#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

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

'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.
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.btnShowDialog = New System.Windows.Forms.Button
'
'btnShowDialog
'
Me.btnShowDialog.Location = New System.Drawing.Point(128, 232)
Me.btnShowDialog.Size = New System.Drawing.Size(96, 24)
Me.btnShowDialog.Text = "Show Dialog"
'
'Form1
'
Me.Controls.Add(Me.btnShowDialog)
Me.Menu = Me.MainMenu1
Me.Text = "DialogDemo"

End Sub

#End Region

Private Sub btnShowDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDialog.Click
Dim ci As CustomerInfo
Dim dlg As New frmDialog
Dim txt1 As String
dlg.ShowDialog()

If dlg.DialogResult = DialogResult.OK Then
ci = dlg.CustomersInfo

MessageBox.Show(ci.Name.ToString())
MessageBox.Show(ci.Phone.ToString())
End If

dlg.Dispose()

End Sub
End Class

----------------------------------------------------------------------
Code from the 2nd form as a dialog box

Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents btnShowDialog As System.Windows.Forms.Button
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

#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

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

'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.
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.btnShowDialog = New System.Windows.Forms.Button
'
'btnShowDialog
'
Me.btnShowDialog.Location = New System.Drawing.Point(128, 232)
Me.btnShowDialog.Size = New System.Drawing.Size(96, 24)
Me.btnShowDialog.Text = "Show Dialog"
'
'Form1
'
Me.Controls.Add(Me.btnShowDialog)
Me.Menu = Me.MainMenu1
Me.Text = "DialogDemo"

End Sub

#End Region

Private Sub btnShowDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDialog.Click
Dim ci As CustomerInfo
Dim dlg As New frmDialog
Dim txt1 As String
dlg.ShowDialog()

If dlg.DialogResult = DialogResult.OK Then
ci = dlg.CustomersInfo

'I KEEP GETTING THE ERROR FROM THE LINES BELOW
MessageBox.Show(ci.Name.ToString())
MessageBox.Show(ci.Phone.ToString())
End If

dlg.Dispose()

End Sub
End Class

sgt_pinky
01-05-2005, 03:42 PM
Take out the dlg.Dispose()

That should fix your problem. You have a strange structure problem though. The dialog will still be in memory, but you will have to restructure your program to solve that problem.

Wolfgard
01-06-2005, 07:47 AM
Hmmm..even after removing the dlg.Dispose, I still get the same error at 'MessageBox.Show(ci.Name.ToString())'. Any idea why? Seems like the 'ToString' is causing the problem.

Wolfgard
01-06-2005, 09:12 AM
If anybody has some simple code to pass data between forms in .NET CF, please help. I'm abit desperate here. I've tried everything and I still get the same error:(

Dennis DVR
01-06-2005, 09:34 AM
If anybody has some simple code to pass data between forms in .NET CF, please help. I'm abit desperate here. I've tried everything and I still get the same error:(

Look here
http://www.xtremevbtalk.com/showthread.php?t=147563

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum