Results 1 to 11 of 11

Thread: diff between me.control and _control ??

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397

    diff between me.control and _control ??

    what is the difference between using me.controlname and _controlname?

  2. #2
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: diff between me.control and _control ??

    Nothing at all. Just like there is no difference between these two statements:
    VB Code:
    1. Dim MyPoint1 As System.Drawing.Point
    2. Dim MyPoint2 As Point ' Assuming you have System.Drawing imported

    The fully qualified name is usually better because it makes things easier to read and understand. It is good coding practice to include it.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

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

    Re: diff between me.control and _control ??

    The underscore is used to indicate that a variable is a class member as opposed to a local variable. Personally, I generally don't use it for the same reasons that I don't use Hungarian notation. It just isn't needed in the modern IDE. The one time I do use it is if I am exposing a variable through a property. It allows you to give the variable and property basically the same name, e.g.:
    VB Code:
    1. Private _someVar As String
    2.  
    3. Public Property SomeVar() As String
    4.     Get
    5.         Return Me._someVar
    6.     End Get
    7.     Set
    8.         Me._someVar = Value
    9.     End Set
    10. End Property
    Using Me also identifies a variable as being a member but that's not why I use it. I use it to get Intellisense. In the example above, if I didn't use Me I would have had to type "_someVar". Because I used Me I would only have to type "me._" and Intellsense would show me the variable. The Intellisense in C# 2005 is smart enough to give you help from the first letter you type, making use of "this" unnecessary, but all other versions (VB and C#) don't.
    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
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: diff between me.control and _control ??

    Ctrl-Space invokes Intellisense immediately. If you've typed some chars already, it uses what's typed as a starting point.... if you haven't, then you get the intellisense with everything in it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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

    Re: diff between me.control and _control ??

    Quote Originally Posted by techgnome
    Ctrl-Space invokes Intellisense immediately. If you've typed some chars already, it uses what's typed as a starting point.... if you haven't, then you get the intellisense with everything in it.

    -tg
    Now that I didn't know. You is da gnome dat knows.
    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

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: diff between me.control and _control ??

    Not only that but it works in VB6 VS2002/2003/2005 .... and probably earlier versions of VS too.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Re: diff between me.control and _control ??

    Isn't is easier to type "me." and then select the variable name you are looking for that type it's name? I always use me.variableName, although the code looks annoying sometimes because of this...
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  8. #8
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: diff between me.control and _control ??

    Quote Originally Posted by jmcilhinney
    Now that I didn't know. You is da gnome dat knows.
    I thought I might mention that Ctrl+J will give you a list of all possible variables/properties/methods/etc no matter where your cursor is in the code. Ctrl+Space does the same thing, except it also attempts to make a prediction based on what you already have typed in, and will fill it in for you if it finds only one possible match.

    Also, Ctrl+I will give you infromation about the current variable. Such as wether its data type.
    Last edited by eyeRmonkey; Apr 4th, 2006 at 10:36 PM.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: diff between me.control and _control ??

    Now that I didn't know. You is da mon-kay dat knows.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: diff between me.control and _control ??

    Quote Originally Posted by techgnome
    Now that I didn't know. You is da mon-kay dat knows.

    -tg
    Seems to me that it might be beneficial for me to make a list of keyboard shortcuts. But, unlike my VB6 to .NET equivalent chart, the shortcuts are probably possible to find online.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: diff between me.control and _control ??

    W.R.T. the first post, Me.controlname and _controlname are two different variables so there's a lot of difference in fact

    As John said, the underscore prefix is just a notation, used to indicate a private member variable.

    You don't want to get too carried away with underscores as in many contexts anything more than a single underscore prefix denotes an indentifier as being reserved for the compiler.

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