|
-
Mar 8th, 2009, 01:51 AM
#1
Thread Starter
Lively Member
How do I get this declared
Hi all,
I have this code, and in a nutshell, I can not seem to figure out where I need to declare the KBR_Host.
I don't know the correct terminology, but I am trying to set the usercontrol so when the "New" is invoked, it calls a host, so I can communicate between usercontrols.
I have attached two screen shots, one of the error, and one of the code where I thought I should have declared it.
Can anybody let me know where I am going wrong?
Thanks
Brent
-
Mar 8th, 2009, 04:42 AM
#2
Re: How do I get this declared
The problem I see here is that while the object is declared, it is not initialized. You need to set it something (in this case, New MAIN.)
Basically, every object you use must be initialized before it can be used.
-
Mar 8th, 2009, 04:58 AM
#3
Re: How do I get this declared
Well if you look at the screenshot with the "Sub New" (the constructor, as it is called).
You take one parameter called "Host" which is of type Main. Now it is up to you what you want to do with that parameter. Do you want to keep a reference to it inside the class? If so you'd declare a class level variable for it:
Code:
Public Dog
Private myCollar As Accessory
Public Sub New(ByVal collar As Accessory)
Me.myCollar = collar
End Sub
End Class
This way we keep a reference to what was passed into the constructor throughout the lifetime of the class. We can perform operations on this object right away, or later.
If you'd rather perform operations on the object directly in the constructor, then there is no need to assign it to anything, just perform operations on the parameter itself.
The other error on the other hand is a bit more odd, you're trying to pass something into the forms constructor but it does not exist. We can not tell you where you should declare it, we can just tell you that it needs to come from somewhere...
One wild guess I can make is just to tell you to declare it right above that line and instantiate it with the 'New' keyword. That'll simply create a new instance of that class, but that might not be what you want.
-
Mar 9th, 2009, 12:40 AM
#4
Re: How do I get this declared
 Originally Posted by Campion
The problem I see here is that while the object is declared, it is not initialized. You need to set it something (in this case, New MAIN.)
Basically, every object you use must be initialized before it can be used.
For clarity it's important to use correct terminology. You don't declare objects. You declare variables. You then initialise the variable by assigning an object to it. You must create an object to be able to assign it to a variable. You instantiate a class, which means creating an instance of that class. The instance of the class is the object.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|