By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

create form object in class2.vb

P: n/a
i have :
mainform
form2 had 2 textbox
class1.vb
class2.vb
how do i create form2 into class2.vb?
i couldn't do better. this is what i do.

in class2.vb
public class class2
public frm2 as form2

sub new()
MyBase.GetType()
frm2 = new form2
frm2.mdiparent !! <===== i wanted frm2 to be mdichild
end sub

Private Sub _Connection_onSeverMessage(ByVal szText As String) Handles
_Connection.onSeverMessage
DisplayMessage(frm2.text= szText.ToString)
End Sub

but i got error problem. it is comming from form2.
An unhandled exception of type 'System.NullReferenceException' occurred
in system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.

in class1.vb. i called from class2
Select Case C(1).Trim
Case "001" To "014", "251" To "272", "372" To "377",
"401", "422", "462", "468", "503"
Dim intA As Integer = CLi.IndexOf(Nick, 0)
RaiseEvent onSeverMessage(CLi.Substring(intA +
Nick.Length).ToString())

regards


Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Supra" <su*****@rogers.com> schrieb:
i have :
mainform
form2 had 2 textbox
class1.vb
class2.vb
how do i create form2 into class2.vb?
i couldn't do better. this is what i do.

in class2.vb
public class class2
public frm2 as form2

sub new()
MyBase.GetType()
frm2 = new form2
frm2.mdiparent !! <===== i wanted frm2 to be mdichild
end sub

Private Sub _Connection_onSeverMessage(ByVal szText As String) Handles
_Connection.onSeverMessage
DisplayMessage(frm2.text= szText.ToString)
End Sub

but i got error problem. it is comming from form2.
An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.

You will have to make a reference to your MDI container available to your
'Class2', for example in a method parameter or a property:

\\\
Private m_MdiParent As Form

Public Sub New(ByVal MdiParent As Form)
m_MdiParent = MdiParent
End Sub

Public Sub ConnectionServerMessage(...) Handles...
Dim f As New Form2()
f.MdiParent = m_MdiParent
f.Show()
End Sub
///

Usage (in MDI container):

\\\
Dim c As New Class2(Me)
....
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
i
to herfried:
how will i do in class1 from class 2
Select Case C(1).Trim
Case "001" To "014", "251" To "272", "372" To "377",
"401", "422", "462", "468", "503"
Dim intA As Integer = CLi.IndexOf(Nick, 0)
RaiseEvent onSeverMessage(CLi.Substring(intA +
Nick.Length).ToString()) <===this data would not dispaly

regards,

Herfried K. Wagner [MVP] wrote:
"Supra" <su*****@rogers.com> schrieb:

i have :
mainform
form2 had 2 textbox
class1.vb
class2.vb
how do i create form2 into class2.vb?
i couldn't do better. this is what i do.

in class2.vb
public class class2
public frm2 as form2

sub new()
MyBase.GetType()
frm2 = new form2
frm2.mdiparent !! <===== i wanted frm2 to be mdichild
end sub

Private Sub _Connection_onSeverMessage(ByVal szText As String) Handles
_Connection.onSeverMessage
DisplayMessage(frm2.text= szText.ToString)
End Sub

but i got error problem. it is comming from form2.
An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.

You will have to make a reference to your MDI container available to your
'Class2', for example in a method parameter or a property:

\\\
Private m_MdiParent As Form

Public Sub New(ByVal MdiParent As Form)
m_MdiParent = MdiParent
End Sub

Public Sub ConnectionServerMessage(...) Handles...
Dim f As New Form2()
f.MdiParent = m_MdiParent
f.Show()
End Sub
///

Usage (in MDI container):

\\\
Dim c As New Class2(Me)
...
///


Nov 21 '05 #3

P: n/a
if i added this...the datas will blanked

Public Sub ConnectionServerMessage(...) Handles...
Dim f As New Form2() <=== added
f.MdiParent = m_MdiParent<===added
DisplayMessage(nStatus.rtbStatus, szText.ToString)
' f.Show()<= rem this
End Sub

regards

Supra wrote:
i
to herfried:
how will i do in class1 from class 2
Select Case C(1).Trim
Case "001" To "014", "251" To "272", "372" To
"377", "401", "422", "462", "468", "503"
Dim intA As Integer = CLi.IndexOf(Nick, 0)
RaiseEvent onSeverMessage(CLi.Substring(intA +
Nick.Length).ToString()) <===this data would not dispaly

regards,

Herfried K. Wagner [MVP] wrote:
"Supra" <su*****@rogers.com> schrieb:

i have :
mainform
form2 had 2 textbox
class1.vb
class2.vb
how do i create form2 into class2.vb?
i couldn't do better. this is what i do.

in class2.vb
public class class2
public frm2 as form2

sub new()
MyBase.GetType()
frm2 = new form2
frm2.mdiparent !! <===== i wanted frm2 to be mdichild
end sub

Private Sub _Connection_onSeverMessage(ByVal szText As String) Handles
_Connection.onSeverMessage
DisplayMessage(frm2.text= szText.ToString)
End Sub

but i got error problem. it is comming from form2.
An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.

You will have to make a reference to your MDI container available to your
'Class2', for example in a method parameter or a property:

\\\
Private m_MdiParent As Form

Public Sub New(ByVal MdiParent As Form)
m_MdiParent = MdiParent
End Sub

Public Sub ConnectionServerMessage(...) Handles...
Dim f As New Form2()
f.MdiParent = m_MdiParent
f.Show()
End Sub
///

Usage (in MDI container):

\\\
Dim c As New Class2(Me)
...
///


Nov 21 '05 #4

P: n/a
i don't needed to used this:
Dim c As New Class2(Me)
regards

Supra wrote:
if i added this...the datas will blanked

Public Sub ConnectionServerMessage(...) Handles...
Dim f As New Form2() <=== added
f.MdiParent = m_MdiParent<===added
DisplayMessage(nStatus.rtbStatus, szText.ToString)
' f.Show()<= rem this
End Sub

regards

Supra wrote:
i
to herfried:
how will i do in class1 from class 2
Select Case C(1).Trim
Case "001" To "014", "251" To "272", "372" To
"377", "401", "422", "462", "468", "503"
Dim intA As Integer = CLi.IndexOf(Nick, 0)
RaiseEvent onSeverMessage(CLi.Substring(intA +
Nick.Length).ToString()) <===this data would not dispaly

regards,

Herfried K. Wagner [MVP] wrote:
"Supra" <su*****@rogers.com> schrieb:
i have :
mainform
form2 had 2 textbox
class1.vb
class2.vb
how do i create form2 into class2.vb?
i couldn't do better. this is what i do.

in class2.vb
public class class2
public frm2 as form2

sub new()
MyBase.GetType()
frm2 = new form2
frm2.mdiparent !! <===== i wanted frm2 to be mdichild
end sub

Private Sub _Connection_onSeverMessage(ByVal szText As String) Handles
_Connection.onSeverMessage
DisplayMessage(frm2.text= szText.ToString)
End Sub

but i got error problem. it is comming from form2.
An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.


You will have to make a reference to your MDI container available to your
'Class2', for example in a method parameter or a property:

\\\
Private m_MdiParent As Form

Public Sub New(ByVal MdiParent As Form)
m_MdiParent = MdiParent
End Sub

Public Sub ConnectionServerMessage(...) Handles...
Dim f As New Form2()
f.MdiParent = m_MdiParent
f.Show()
End Sub
///

Usage (in MDI container):

\\\
Dim c As New Class2(Me)
...
///


Nov 21 '05 #5

P: n/a
Supra,

"Supra" <su*****@rogers.com> schrieb:
i don't needed to used this:
Dim c As New Class2(Me)


Problem solved?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6

P: n/a
yes. i removed this

Dim c As New Class2(Me)
regards
ur example code is working... i can only do like this
Display ( frm.textbox1, "bla bla bla bla ",sztext)
but not in this:

Select Case C(1).Trim
Case "001" To "014", "251" To "272", "372" To "377","401", "422", "462", "468", "503"
Dim intA As Integer = CLi.IndexOf(Nick, 0)
RaiseEvent onSeverMessage(CLi.Substring(intA + Nick.Length).ToString())<===this data would not dispaly

regards
Herfried K. Wagner [MVP] wrote:
Supra,

"Supra" <su*****@rogers.com> schrieb:

i don't needed to used this:
Dim c As New Class2(Me)


Problem solved?


Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.