The following table shows correspondences between previous integer types and Visual Basic.NET 7.0 types.
|Integer Size||Previous Visual Basic Type and Type Character||Visual Basic.NET 7.0 Type and Type Character||.NET Framework and Runtime Type|
|16 bits, signed||
|32 bits, signed||
|64 bits, signed||(none)||
Since a data type in VB7 is a wrapper of the corresponding type in the .NET Framework, you can continue writing the following code.
Dim x As Integer
which will translate into the following.
Dim x As Int32
Note that on 32-bit systems, 32-bit integer operations are faster than either 16-bit or 64-bit integer operations. This means that in VB7,
Integer is the most efficient and
fundamental numeric type. You can improve performance in your applications by changing your
Long declarations to
Integer when you migrate to VB7.
Currency data type is not supported in VB7. Instead, there is a new data type named
Decimal, which can handle more digits on both sides of the decimal point, for all money variables and calculations. The
Decimal data type is also directly supported by the .NET Framework and Runtime.
What are your experiences with migrating from VB 6 to VB .NET?
In VB6 variants served as the universal data type. In VB7 variants no longer exist. In VB7
Object is the universal data type. All functionality of variants is supplied by
Object. Since there is no longer a variant data type, the
VarType function -- the function that in
VB6 was used to get an integer that indicates the subtype of a variable -- also ceases to exist. As a replacement, you can use the Object class's
GetType method that returns an
object of type
Type. You can then use the
GetTypeCode method to obtain
TypeCode enumeration. Using the latter, you can then get the type code of an object. You may think this is a much more complicated process, but this can be done in a
single line of code.
Dim aType As Byte ' replace Byte with any other type
Dim TypeCode As Integer ' an integer to hold the type code
TypeCode = Type.GetTypeCode(aType.GetType)
aType is a
TypeCode will have a value of 6. If
aType is an
Typecode will be 9.
String data type is a wrapper for the
System.String class that derives directly from
System.Object. String manipulation functions in VB6, such as
etc, are replaced by the methods in the
System.String class. The following lists changes to the old
In VB6 you can specify the length of a string in its declaration. This causes the string to have a fixed length.
Dim Name As String * 100
In VB7, you cannot declare a string to have a fixed length. You must declare the string without a length. When your code assigns a value to the string, the length of the value determines the length of the string
Dim s As String s = "Hello World" ' Length is 11
String Manipulation Functions
You can still use this function in your Windows applications, but now you can also use the
Length property of the
System.String class. Therefore, if
s is a
String object, you can obtain its length by writing
Left$, Right$, Mid$
Mid$ can be replaced by the
Substring method. This method returns a substring of the instance of the current
String object. This one method is sufficient to do the operations that you used to achieve with
Mid$ For instance, the following shows a
Left$ function and its equivalent of the
Dim s As String s = Left$("Hello World", 5) ' returns "Hello"
is equivalent to
Imports System Dim s As String s = "Hello World".Substring(0, 5) ' returns "Hello"
Right$ function is also replaced by the
Substring method. The following VB6 code that uses the
Dim s As String s = Right$(Hello World", 5) ' returns "World"
is equivalent to the following VB7 code:
Imports System Dim s As String, s1 As String s = "Hello World" s1 = s.Substring(s.Length - 5) ' returns "World"
From the two examples, the
Mid$ can easily be replaced by the
Substring method as well.
In VB6, you could use the
Trim$ function as in the following code.
Dim s1 As String, s2 As String s1 = " Hello World " s2 = Trim$(s1)
In VB7, use the
Trim method of the
System.String class, instead.
Imports System Dim s1 As String, s2 As String s1 = " Hello World " s2 = s1.Trim()
LCase$ and UCase$
In VB6, the
LCase$ returns a new string in lower case and the
UCase$ function returns a
new string in upper case. These two functions are complemented by the
methods of the
String class. As an example,
is the same as
returns the same result as
In VB6, the
Replace function is used to replace part of a string with a substring. For example, the following VB6 code will result in "kingkong."
Dim s As String s = Replace("dingdong", "d", "k") ' s = "kingkong"
String class has the
Replace function that does a similar task. For example, the following VB7 code does the same thing.
Dim s as string = "dingdong".Replace("d"c, "k"c)
Note that the
Replace method of the
String class accepts two
Char arguments, not
You can still use the string manipulation functions:
If s1 = s2 Then
which is the same as writing the following:
If s1.Equals(s2) Then
The StringBuilder Class
System.String class represents an immutable string of characters, just like
String in VB6. This means the value of a
String variable cannot be modified. If you try to modify a
String, a new
String object is created instead. Remember that object creation is an expensive operation. The .NET Framework also provides the
System.Text.StringBuilder class that is more efficient to work with. For more information, see the .NET Framework Reference.