From the past to the future, from Visual and Basic to NET (3)
10. Create controls for runtime dynamics. VB. Net no longer directly supports the array of controls like VB6, with VB. NET will have different implementations and need more code, VB. NET's implementation mechanism Some like Java is implemented. I have always doubts whether MS moves directly from WFC in VJ to VS. Net.
Past VB
============================================================================================================================================================================================================= ====
Private subdaddButton_Click (INDEX AS INTEGER)
Static Counter as in
Counter = Counter 1
IF counter <4 THEN
Load cmddbutton (Counter)
WITH CMDADDBUTTON (Counter - 1)
cmdaddbutton (counter) .MOVE_
.Left .width _
(10 * screen.twipsperpixelx), .top
End with
cmdaddbutton (counter) .visible = true
END IF
End Sub
Now VB.NET
============================================================================================================================================================================================================= ====
(First implementation)
Private sub btnaddButton_Click (byval sender as _
System.Object, ByVal e as system.eventargs_
Handles btnaddbutton.click
Static Counter as integer = 1
Static lastbutton as system.windows.Forms.Button
Counter = 1
If lastbutton is nothing then
LastButton = btnaddbutton
END IF
IF counter <4 THEN
Dim b as new system.windows.Forms.Button ()
With lastbutton
B.Width = .width
B.Text = .text
Controls.add (b)
B.LEFT = .left .width 10
B.TOP = .top
LastButton = B
End with
AddHandler B.Click, Addressof Me.btnaddButton_Click
END IF
End Sub
(Second implementation)
Private sub btnnewadd_click (byval sender as _system.Object, byval e as system.eventargs)
Handles btnnewadd.click
Dim b as new system.windows.Forms.Button ()
With sender
B.Width = .width
B.Text = "Click ME!"
Controls.add (b)
B.LEFT = .left .width 10
B.TOP = .top
End with
AddHandler B.Click, Addressof Me.NewButtonClick
End Sub
Use GetChildIndex to get controls in the control array.
Private subnewbuttonclick (byval sender as _
System.Object, ByVal e as system.eventargs
Msgbox ("A New Button Was Clicked! THE INDEX OF" _
"this Button IS:" & me.controls.getchildindex _
(sender))
End Sub
11. Definition of variables and arrays.
VB6 variable definition is very magical, when I start with VB, I always thought that DIM X, Y AS String is the same. Waiting, I don't like to use DIM X as string, y as string, and prefer to define two lines. Now VB. The variables defined in the same statement in the NET must be the same type, that is, DIM X as integer, y as string is not allowed. The most satisfied is VB. Net begins to support such syntax: DIM X as integer = 24, waiting for many years. The definition of arrays, especially initialization, also improved, and now you can initialize the value while defining, saving a loop variable and making a for loop, and the subscript is based on zero, sudden array can only be Based on zero subscript, all arrays are started by zero.
Past VB
============================================================================================================================================================================================================= ====
DIM X as integer
X = 100
DIM MyArray (10) AS Integer (there are 11 elements that actually have
For i = 0 TO 10
MyArray (i) = i
NEXT
DIM MyArray1 (10) AS INTEGER
DIM MyArray2 (10) AS Integer
For i = 0 TO 10
MyArray 1 (i) = i
NEXT
For i = 0 TO 10
MyArray 2 (i) = MyArray1 (i)
NEXT
Now VB.NET
============================================================================================================================================================================================================= ==== DIM X as integer = 100
Dim MyArray (10) as integer = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) (10 elements of total)
DIM MyArray1 (10) AS Integer = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
DIM MyArray2 (10) as integer = myarray1
12. Start support structured error handling, introducing new try, catch, finally statement and there is a throw expression, so you can write a lot of on Error Goto in multiple layers, don't expect GOTO. VB. Net still supports the original non-mechanism's error handling statement, such as interesting on Error Goto 0, ON Error ResMe next, and more. However, it seems very interesting when there is a function of structural and non-structural errors. Just like the farmers in the new Empire 2, the code defense increases Double.
In general, VB.NET is more simple and less code than the previous VB, but you also need to know more of more objects and objects. Can't say VB. Net is better or not good than VB, sometimes I want to put VB and VB. Net is all different languages, perhaps more actual, so we will not delume the current VB program for small modifications can run on the DOTNET platform.
Although all currently running applications can be upgraded to DOTNET, this does not hinder you to learn a language, accept a change; in fact, regardless of the development of VB, you can master and adapt to Visual Studio for you. Net will be a curve evolution, whether it is still the future.