I see there is a use of [qote][/quote]Code:Protected sub ...
What does this mean? Is this the equiv of friend?
What about Overloads and Overrides??
What the hell are these?
Printable View
I see there is a use of [qote][/quote]Code:Protected sub ...
What does this mean? Is this the equiv of friend?
What about Overloads and Overrides??
What the hell are these?
Protected is sort of like Public but means it can only be accessed from tis own or an inherited class.
Overrides means that it replaces a sub/function of the same name and runs the overrides version when the orginal would be called.
Overloads allows you to define multiple subs/functions of the same name but different parameters. .NET will know which one to access depending on the parameter type(s) you pass.
I think that is the easiest way to expoain them. Got it?
SWEAT!
Does this mean that I can write a procedure to replace the class' initialize event that accepts parameters?
yes - you can do that. Although you use the "constructor" (replaces class initialize).
You can also overload it, so that it can accept different parameters
for example,
VB Code:
Public Sub New(ByVal strName As String) ... End Sub Public Sub New(ByVal blnSwitch1 As boolean, blnSwitch2 as Boolean) ... End Sub
Sorry, I haven't had time to play with this yet, but will the calling application see the change when creating new objects?
for example:
Previously we did this:
What do we do now if our object creation has parameters?Code:set obj = new Class
You would now be able to do this...
VB Code:
Dim objA as New clsClassA(strParam)
I also notice that when adding a button to a form, the onclick event appears with a new guy, "Handles".
What is the significance of this?
Its the "Handles" bit that actually tells you the event (or events) that is being handled. The fact that the sub is called button1_click (or whatever it is) is actually irrelevent - you could rename it and the program wouldnt change.
If you wanted the same method to handle more than one event - ie this is how you would do it. (there are no longer control arrays in vb.Net).
For example,
VB Code:
Private Sub cmdNextPrior_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click, cmdPrior.Click Dim oButton As System.Windows.Forms.Button oButton = CType(sender, System.Windows.Forms.Button) If oButton.Name = "cmdNext" Then If mintOffset < mcolErr.Count - 1 Then mintOffset = mintOffset + 1 DisplayException() End If End If If oButton.Name = "cmdPrior" Then If mintOffset > 0 Then mintOffset = mintOffset - 1 DisplayException() End If End If End Sub
This code handles the click event of two buttons. The "sender" argument is used to determine which of the two buttons were pressed.
This is pretty cool.
But if there are no control arrays anymore, how do you create controls dynamicaly? And then how do you receive an event from the new control?
I also noticed the use of
System.Windows.Forms.Button
What is the difference between this and
Button
:confused:
First things first.
There is no difference between Button and System.Windows.Form.Button - it's a namespace thing. If your assembly imports System.Windows.Form, then you have no need to type System.Windows.Form before Button.
And now for something completely different.
An example of dynamically creating a control :-
VB Code:
Dim oNewButton as New Button 'Set it up on the form oNewButton.Location = New System.Drawing.Point(200, 152) oNewButton.Size = New System.Drawing.Size(80, 32) oNewButton.Text = "Press Me" 'Add it to the Forms control collection Me.Controls.Add(oNewButton) 'Hook it up to the event handler AddHandler oNewButton.Click AddressOf Me.Button_Click