Converting Data Types
VB .NET offers four ways to change one data type into another. The .ToString
method is designed to convert any numeric data type into a text string.
The second way to convert data is to use the traditional VB functions: CStr(),
CBool(), CByte(), CChar(), CShort(), CInt(), CLng(), CDate(), CDbl(),
CSng(), CDec(), and CObj(). Here is an example:
Dim s As String
Dim i As Integer = 1551
s = CStr(i)
MessageBox.Show(s)
The third way is to use the Convert method, like this:
Dim s As String
Dim i As Integer = 1551
s = Convert.ToString(i)
MessageBox.Show(s)
The fourth way uses the CType function, with this syntax:
Dim s As String
Dim i As Integer = 1551
s = CType(i, String)
MessageBox.Show(s)
No comments:
Post a Comment