Results 1 to 4 of 4

Thread: How do I get this declared

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Location
    Perth, Australia
    Posts
    101

    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
    Attached Images Attached Images   

  2. #2
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    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.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How do I get this declared

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width