Some examples of conversion functions of VB6 to VB.NET

Remove X characters left:

'VB6
Dim a As Integer = 12345
Debug.WriteLine (Microsoft.VisualBasic.Left (a, 2))

'VB.NET
Dim a As Integer = 12345
Debug.WriteLine (num.ToString.Substring (0, 2))

Remove X characters from the middle of a string:

'VB6
Dim a As Integer = 12345
Debug.WriteLine (Microsoft.VisualBasic.Mid (a, 1, 1))

'VB.NET
Dim a As Integer = 12345
Debug.WriteLine (num.ToString.Substring (0, 1))

Check what the ascii code of a character:

'VB6
Debug.WriteLine (Asc ( "A"))

'VB.NET
Debug.WriteLine (Convert.ToByte ( "A"))

Converts an ascii code in your character:

'VB6
Debug.WriteLine (Chr (65))

'VB.NET
Debug.WriteLine (Convert.ToChar (65))

Displays the current date / time:

'VB6
Debug.WriteLine (Now.ToString)

'VB.NET
Debug.WriteLine (DateTime.Now.ToString)

Displays a message on the screen:

'VB6
MsgBox ( "test!")

'VB.NET
MessageBox.Show ( "test!")

Converts to integer:

'VB6
Debug.WriteLine (CInt ( "123"))

'VB.NET
Debug.WriteLine (Integer. Parse ( "123"))

Convert to String:

'VB6
Dim a As Integer = 12345
Debug.WriteLine (CStr (num))

'VB.NET
Dim a As Integer = 12345
Debug.WriteLine (num.ToString)

Checks whether an expression is numeric:

'VB6
Dim a As String = "12345"
If IsNumeric (num) Then
'True
End If

'VB.NET
Dim a As String = "12345"
Dim result As Integer
If Integer. TryParse (num, result) Then
'True result and the variable
'Gets the result in whole
End If

Checks whether an expression is a valid date:

'VB6
Dim data As String = "10/2/2010"
If IsDate (date) Then
'True
End If

'VB.NET
Dim data As String = "10/2/2010"
Dim dt As DateTime
If DateTime.Parse (date, dt) Then

'True and the variable dt
Gets the result as DateTime
End If

There are many more examples, but these serve to show some of the ways how we can replace the former functions of VB6 and start the program. NET way ”

Hope that helps!

Leave a Reply

Your email address will not be published. Required fields are marked *