|
-
Jul 19th, 2009, 12:06 PM
#1
Thread Starter
New Member
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,
-
Jul 19th, 2009, 12:21 PM
#2
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.
-
Jul 19th, 2009, 12:26 PM
#3
Thread Starter
New Member
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.
-
Jul 19th, 2009, 02:08 PM
#4
Re: My Questions
Sharon, you may also want to note that you can only override a base method if it is declared Overridable.
-
Jul 19th, 2009, 11:03 PM
#5
Re: My Questions
Can someone do my homework for me too?
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
|