Wolfgard
01-05-2005, 08: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
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