lunaclover
Programmer
- Jun 22, 2005
- 54
Hi all -
I have three checkboxes 'chk1' that I have on 3 forms. When checked by user from any form it opens the same form (FrmT) using the code:
frmT is a form consisting mainly of a listbox whose output varies depending on the combinations of chks selected from whichever form it is accessed by. Well, actually that's my problem. That's what I want it to do, and i'm trying to use With statements to make it do it.
Here is the code I'm using.
Then I use:
It works fine when there is one With Statement, but when I add another one, like this,
and
it says no.
Say I am on form2, and I check the chk1 - it will highlight
[highlight]rb6.Checked = .rb6.Checked[/highlight] and say
*******An unhandled exception of type 'System.NullReferenceException' occurred in Products.exe
Additional information: Object reference not set to an instance of an object.***********
If I'm on form3 and check the chk1 on this form it will highlight
[highlight]rb1.Checked = .rb1.Checked[/highlight] and give the same error.
I know it's because it doesn't know what form2 is when I am calling frmT from form 3, and vice versus, but I'm not sure how to just make it ignore that object and do the code within the right object. For example, if frm2.chk1 then don't care about the frm3 object code, and only be concerned with the
Any suggestions/insight/sarcasm? Please let me know if this isn't clear. Any help would of course be appreciated greatly, as always!
Lunaclover
I have three checkboxes 'chk1' that I have on 3 forms. When checked by user from any form it opens the same form (FrmT) using the code:
Code:
If chk1.Checked Then
Dim fT As New FrmT(Me)
fT.Show()
End If
Here is the code I'm using.
Code:
Public Class FrmT
Inherits System.Windows.Forms.Form
[b]Private frm2 As Form2[/b]
#Region " Windows Form Designer generated code "
Public Sub New(ByVal [b]f2 As Form2[/b])
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
[b]frm2 = f2[/b]
End Sub
Then I use:
Code:
Private Sub FrmT_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With frm2
rb1.Checked = .rb1.Checked
rb2.Checked = .rb2.Checked
rb3.Checked = .rb3.Checked
rb4.Checked = .rb4.Checked
rb5.Checked = .rb5.Checked
End With
If rb1.checked then
lstbox1.items.add("stuff")
end if
It works fine when there is one With Statement, but when I add another one, like this,
Code:
Public Class FrmThermostat
Inherits System.Windows.Forms.Form
Private frm2 As Form2
[b]Private frm3 As Form3[/b]
#Region " Windows Form Designer generated code "
Public Sub New(ByVal f2 As Form2)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
frm2 = f2
End Sub
[b] Public Sub New(ByVal f3 As Form3)
MyBase.New()
frm3 = f3
End Sub [/b]
and
Code:
Private Sub FrmT_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With frm2
rb1.Checked = .rb1.Checked
rb2.Checked = .rb2.Checked
rb3.Checked = .rb3.Checked
rb4.Checked = .rb4.Checked
rb5.Checked = .rb5.Checked
End With
If rb1.checked then
lstbox1.items.add("stuff")
end if
[b]
With frm3
rb6.Checked = .rb6.Checked
rb7.Checked = .rb7.Checked
rb8.Checked = .rb8.Checked
rb9.Checked = .rb9.Checked
rb10.Checked = .rb10.Checked
End With
If rb8.checked then
lstbox1.items.add("stuff")
end if
[/b]
it says no.
Say I am on form2, and I check the chk1 - it will highlight
[highlight]rb6.Checked = .rb6.Checked[/highlight] and say
*******An unhandled exception of type 'System.NullReferenceException' occurred in Products.exe
Additional information: Object reference not set to an instance of an object.***********
If I'm on form3 and check the chk1 on this form it will highlight
[highlight]rb1.Checked = .rb1.Checked[/highlight] and give the same error.
I know it's because it doesn't know what form2 is when I am calling frmT from form 3, and vice versus, but I'm not sure how to just make it ignore that object and do the code within the right object. For example, if frm2.chk1 then don't care about the frm3 object code, and only be concerned with the
Code:
With frm2
*code*
End With
Any suggestions/insight/sarcasm? Please let me know if this isn't clear. Any help would of course be appreciated greatly, as always!
Lunaclover