Click here to Skip to main content
14,932,457 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi programmers,

Please help me with this little problem.
I am developing a small VB.NET project which has several forms.
Each form has a private sub similar to the one shown below:

VB
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
       If TabControl1.SelectedTab Is TabPage1 Then
           If Estado1 = True Then
               Cargador(Me)
               Estado1 = False
           End If
       ElseIf TabControl1.SelectedTab Is TabPage2 Then
           If Estado2 = True Then
               Cargador(Me)
               Estado2 = False
           End If
       ElseIf TabControl1.SelectedTab Is TabPage3 Then
           If Estado3 = True Then
               Cargador(Me)
               Estado3 = False
           End If
       ElseIf TabControl1.SelectedTab Is tabpage_N Then
       'etc...
Endif
   End Sub


I have the following codes inside a module:
VB
module module1
Public Sub Cargador(ByVal MyForm1 As Form)
ReDim CtlPlc(MyForm1.Tabcontrol1.SelectedTab.Controls.Count)

'codes to do something here

end sub
end module


As you can see, the Cargador subroutine is being called frequently from every
form. I know that I cannot call the Cargador sub with a simple 'Cargador (Me)'.
I still need to pass other argumments for the 'TabControl1.SelectedTab'.
The problem is that I don't know how to reference Tabcontrol1.SelectedTab in
the Cargador's sub declaration.
The compiler highlights the 'TabControl' in the CtlPlc ReDim statement and gives me an error that says:
TabControl1 is not a member of system.windows.forms.form

I am new to programming. Any help will be appreciated.
Thanks in advance.
Posted
Updated 10-Jun-12 10:26am
v3
Comments
   
Well, maybe it's not a member. How can we know that without seeing your MyForm1 code? Start with giving everything human-readable names, all those "1" are illegal from the style point, see Microsoft naming conventions. :-)
--SA
André Kraak 9-Jun-12 4:09am
   
Edited question:
Added pre tags

First of all, remove the part of procedure: If TabControl1.SelectedTab Is TabPage1 Then ... End if and take a look here:

VB
If Estado1 = True Then 
Cargador (TabControl1.SelectedPage)
Estado1 = False
End If


I haeven't see the rest part of if -> else. Probably you can use it:
VB
Cargador (TabControl1.SelectedPage)
Estado1 = Not Estado1 
End If


Changed Sub Cargador could see like this:
VB
Public Sub Cargador(ByVal tp As TabPage)
ReDim CtlPlc(tp.Controls.Count)
 
'codes to do something here

End sub
   
v2
Comments
Member 8992910 10-Jun-12 19:32pm
   
Losmac,
Thanks for your sugestions. I removed the redundant codes you mentioned; However, calling the public sub Cargador with the
statement 'Cargador(TabControl1.SelectedPage)' when Sub Cargador is (ByVal tp as TabPage) produces the same original error from the compiler:'TabControl1 is not a member of System.Windows.forms.form' Thanks.
Now I have inside the module the following:

XML
module module1
Public Sub Cargador(ByVal TP As TabPage)
ReDim CtlPlc(TP.Controls.Count)

'codes to do something here

end sub
end module

From the main program I call this public sub with

Cargador((TabPage1)
Cargador((TabPage2)
Cargador((TabPage3)
etc...
It depends on the control I want to pass as the argument.

The error given previously by the compiler is gone.
The program works fine. No problem at all!!!
Thanks.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900