Problems with this code. Any ideas?

NickJ

Member
Joined
Apr 29, 2005
Messages
21
Programming Experience
Beginner
I have a problem with the code. I think its got something to do with the way its laid out.

Im trying to get the user to enter a number from SetUpFrm which has a comboBox (ProjLstCb) so that the TabControl on Form1 will be populated with that number of TabPages

Here is the code

Dim ProjLstCb As ComboBox
Dim tabCount As Integer = Convert.ToInt16(ProjLstCb.SelectedItem)
Dim Count As Integer
Do Until Count = tabCount
Dim TabPage As New System.Windows.Forms.TabPage
TabPage.Text = "Projector1" & Count.ToString()
'additional code here to add other controls and modify
'properties of each individual tab page
TabSum1.TabPages.Add(TabPage)
Count = Count + 1
Loop

The problem isTabsum1 is on form1 and this code is on SetupFrm, so how do I tell this bit of code to look at form1 for the Tabsum1?

Thanks

Nick
 
You would need to have a reference to form1 in this code. When you instantiate the SetupFrm, pass a reference to form1 as an argument.
VB.NET:
Private frm as form1
Public Sub New(f as form1)
mybase.new
InitializeComponent
frm = f
End Sub
 
 
frm.TabSum1.TabPages.Add(TabPage)
 
thanks for that but this line of code returns an error...

frm.TabSum1.TabPages.Add(TabPage)

This is the error...

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

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

What am i doing wrong
 
Make sure that wherever you declare the SetUpFrm, you pass the reference to form1 like this:

dim frmSetUp as SetUpFrm = New SetUpFrm(Me) 'Use Me if you are doing this from form1. Use whatever variable you have for form1 if you are doing it from somewhere else
 
Back
Top