×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to pass an object to a procedure

How to pass an object to a procedure

How to pass an object to a procedure

(OP)
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.

RE: How to pass an object to a procedure

(OP)
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.

RE: How to pass an object to a procedure

(OP)
Resolved! Thanks.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close