Results 1 to 5 of 5

Thread: My Questions

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    12

    My Questions

    Hi guys,

    I'm very new to Visual Basic and it's concepts so i have have a few questions about the syntax of the lan.:

    1) What is the 'Get' statement and when do you use it?
    2) Whats the difference between public, private, protected etc... when declaring functions and subs.
    3) When would you use the overrides property?

    Thanks in advance,

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: My Questions

    1) I believe the Get statement is only used in Properties. Properties generally both have a Get and Set part. The Get statement is used to retrieve the property value, while the Set statement is used to set the property value:
    Code:
    Private _propertyValue As String
    Public Property MyProperty() As String
       Get
          Return _propertyValue
       End Get
       Set(ByVal value As String)
          _propertyValue = value
       End Set
    End Property
    The Get code is run when you use the following:
    Code:
    Dim str As String
    str = MyProperty
    while the Set code is run when it's the other way around:
    Code:
    MyProperty = "Hello"

    2) They are called access modifiers, you may want to look them up in MSDN. Basically, anything that is declared Private can only be accessed from within the same class (form, control, whatever). Anything declared Public can be accessed from anywhere. There's also Friend, which makes it accessible only from within the same project. For the rest, look them up.

    3) Overrides is not a property. The Overrides statement is used when you override a function/sub/property in a base class. You have a base class when your current class inherits another class.
    As a practical example, all controls (Button, Checkbox, TextBox, etc) inherit (ultimately) from the Control class.

    You may need to inherit a class when you want to extend (or limit) its behavior. For example, you may want to create a Button that changes its icon when clicked. You could of course do that via code in your form, but you can also do it by creating a new class and having it inherit from the Button class. Then, you get all Button behavior automatically. But ofcourse, we don't want it to behave as a button exactly, because then we could just use a regular button. To change it's behavior, we can override the OnClick event, and put some code there to override it's behavior. This is basically the same as using the Click event of the button in your form, except now it will be built into your custom button class.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    12

    Re: My Questions

    Hi Nick,

    Wow, this is extremely helpful and exactly what I was looking for.
    Thank you for taking the time to answer.

  4. #4
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: My Questions

    Sharon, you may also want to note that you can only override a base method if it is declared Overridable.

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

    Re: My Questions

    Can someone do my homework for me too?
    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

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