Results 1 to 5 of 5

Thread: the new class and object

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    2

    the new class and object

    what's the difference between these codes?
    -dim variable as button
    -dim variable as new button
    -dim variable as button = new button

    please describe the "NEW" and how it works , in simple word.

    in defenition a variable as object ,
    what's the difference between these codes?
    -dim variable as object
    -dim variable as system.object
    Imran Hashmi
    www.visionstudio.co.uk
    www.seo-professional.co.uk 0044-7969012441

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: the new class and object

    -dim variable as button
    declares variable as type button, but the variable is set to nothing, and no members of it can be accessed until its constructor (New) is called, or it is set to an existing instance of a button object (like variable = button1, where button1 already existed)

    -dim variable as new button
    same as above except New is being called so you can access its members and work with all the properties of this object and it is not Nothing

    -dim variable as button = new button
    longer way to do above (dim variable as new button)

    as for
    -dim variable as object
    -dim variable as system.object

    these are the same exact thing, but if you are working with the visual studio IDE, then system is automatically added as a project level imports in the project properties. This means anything that has system as its root, does not need system. typed before it (similar to the way you don't need to type me. in a form to access its members, but you can)

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: the new class and object

    Another way to look at the first two is that declaring the variable:

    Dim btn as button

    Simply tells the compiler to set aside enough memory to hold one of these objects. The object isn't actually there. All that is there is enough memory for the object.

    Dim btn as New Button
    and
    Dim btn as button = New Button

    Both of these tell the compiler to create the memory to hold the object, but also create the object in the memory. Either way, the variable is only a pointer to the memory where the object resides. Until you create a NEW object to put in the memory, there isn't anything there. The variable points to nothing until an object is created.
    My usual boring signature: Nothing

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: the new class and object

    sort of like what your signature points to Shaggy

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: the new class and object



    The ultimate 0!
    My usual boring signature: Nothing

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