| |
|
1
Stop Using
Default Properties |
| default
properties are no longer supported. This form
strFirstName =
txtFirstName will not work in VB.NET. You
must use this form instead
strFirstName = txtFirstName.Text |
| |
|
2
Subs and
Functions Require Parentheses () |
In VB6:
ShowMessage “Hello VB6”
Call ShowMessage (“Hello VB6”)
In VB.NET:
ShowMessage (“Hello VB.NET”)
Call ShowMessage (“Hello VB.NET”)
Note: By using MsgBox
function (or any function), you must now always
use parentheses with functions, even if you are
ignoring the return value. |
| |
|
3
Stop
Making Direct References to Controls |
VB has considered
controls on a form to be Public. This will fail
under VB.NET, therefore any code outside the
form reads data from or writes data to the form
must be done through custom property procedures.
Note: Custom property
procedures is not the only way, you could
declaring a control on a form as Public Shared,
but the first way is more professional. |
|
|
|
4
Changes
to Boolean Operators |
VB.NET has introduced a couple of
new operators:
AndAlso and OrElse. |
|
|
|
5
Declaration
Changes |
Dim I, J As Integer
As you’re probably aware, in VB6, J would be an
Integer data type, but I would be a Variant.
In VB.NET, this has changed, so both I and J are
Integers. |
|
In VB6, the only way to
initialize a new variable was to do so on a
separate
line, like this:
Dim x As Integer
x = 5
In VB.NET, you can rewrite this into one line of
code:
Dim x As Integer = 5 |
|
|
|
6
Support
for New Assignment Operators |
In VB6, you incremented X by 1
with the following line of code:
X = X + 1
In VB.NET, you can type an equivalent statement
like this:
X += 1
VB.NET also supports -=,
*=,
/=,
\=, and
^= from a
mathematical standpoint, and
&= for string
concatenation. |
|
|
|
7
ByVal
Is Now the Default |
|
The default way to pass
parameters in VB has always been by reference.
VB.NET using ByVal as a default. |
|
|
|
8
Block-Level
Scope |
A block is any section of code
that ends with one of the words End, Loop, or
Next. The scope of Variable is block level, but
its lifetime is procedure level.
While X < 5
Dim X As Integer
'The variable X is now
visible only within the While loop.
...
End While |
|
|
|
9
While...Wend
Becomes While...End While |
|
If you type Wend, the editor will
automatically change it to End While. |
|
|
|
9
Procedure
Changes: Optional Arguments Require a Default
Value |
|
Optional arguments in VB.NET
require a default value, consequently IsMissing
function is not needed because an optional
argument is guaranteed to have a value. |
|
|
|
10
Static
Not Supported on Subs or Functions |
|
Static is not supported on Subs
or Functions in VB.NET, as a result you
need to place Static in front of each variable
for which you want to preserve the value. |
|
|
|
11
The
Return Statement |
The Return statement can be used
to produce an immediate return from a called
procedure.
Function foo() As Integer
While True
Dim I As Integer
I += 1
If I >= 10 Then
Return I
End If
End While
End Function |
|
|
|
...more points will be added soon! |
|
|