Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass an object to a procedure

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I created a bunch of usercontrol that I need to pass to a generic procedure that will copy and place them on a form.
something like this:

dosomething(usrCtl1)
dosomething(usrCtl2)
dosomething(usrCtl3)

I tried this code but did not work.

private sub dosomething(uc as UserControl)


for i as integer = 0 to 3

Dim myUC as UserControl

if TypeOf uc Is usrCtl1 then
myUC = Trycast(uc, usrCtl1)
elseif TypeOf uc Is usrCtl2 then
myUC = Trycast(uc, usrCtl2)
elseif TypeOf uc Is usrCtl3 then
myUC = Trycast(uc, usrCtl3)
else
myUC = Trycast(uc, usrCtl4)
end if

myUC.name = uc.name & i.tostring
......
next

Been reading thru deep and shallow copy, but quite not there yet, being a .net newbie.
Any help will be greatly appreciated.
 
Ok, I had this code working by implementing a close() function on all my user controls

Public Function clone() As usrCtl1
Return DirectCast(Me.MemberwiseClone(),usrCtl1)
End Function

private sub dosomething(uc as UserControl)

Dim myUC as New Object
for i as integer = 0 to 3

myUC = uc.Clone

myUC.name = uc.name & i.tostring
uc.parent.controls.add(myUC)
......
next

But now I am getting an error when I add the new object to the parent control - child is not a child control of this parent.
Note: I am trying to add it to a tabpage of a tabcontrol where uc is added at design-time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top