Wednesday, 3 July 2013

Conversion Functions VB.NET



Visual Basic supports a number of ways of converting from one type to another. The conversion function would take such a value , String, expression and attempt to convert it. It the conversion is successful , the function would return an appropriate value. 1. CBool :- CBool Stands for Convert to Bool . It converts String , Charcter or numeric expression into boolean value . Synatax :- CBool ( expression ) Example :- Dim a, b As Integer         a = 10         b = 20         Dim check As Boolean         check = CBool(a > b)         MsgBox(check) 2. CByte :- CByte stands for Convert to Byte Data Type. It converts numeric or floating values to byte Data Type.. If fractional part is given in variable-name then it will round off it to integer type. Synatax :- CByte ( variable-name ) Example :- Dim num1 as Double Dim num2 as Byte num1 = 2144.7865789 num2 = VByte( num1 ) Msgbox ( num2 ) 3. CDate :- CDate Stands for Convert to Date type. It converts any valid form date format given as argument to it into Date Syntax :- CDate ( Sting_Variable_Name )
Example :- 
Dim DateString As String 
Dim Finl_Date As Date
DateString = "July 3, 2013"
'The following line converts date format given in Date Type and give
it to Finl_Date
Finl_Date = CDate ( aDateString )
Msgbox ( Finl_Date.tostring())

4. CDbl :- CDbl stands for Convert to Double Data-Type. It converts 
the any given integer value to Double floating value

5. CInt :- CInt Stands for Convert to Integer Date -Type . CInt is 
widely used when converting from numbers or integers entered in string variable to convert it into integers to perform any Arithmetic operations.

Syntax :- 
CInt ( String_Variable )

Example :- 
Dim Var As String = "10" Dim num1, num2 As Integer num1 = CInt(Var) num2 = 10
MsgBox(num1 + num2) 
 
 'It Returns 20




6. CChar :- CChar Stands for Convert to character. It Takes a String 
Variable as input Argument and as it convert it into char so it passes
the first character of specified string varible to a character variable


Syntax :- CChar ( String_Variable )
Example :-
Dim String_variable As String = "bvf" 
Dim char_variable As Char
char_variable = CChar(String_variable)
MsgBox ( char_variable )
7. Cstr :- Cstr stands for convert to string . It converts any  
integer floating value given as input to CStr into string type value
Syntax :-
Cstr ( Variable_Name )
 
Example :-
Dim Str as String
Dim input as integer
input = 12267.9999
Str = Cstr ( input )
Msgbox ( Str ) 
' It Returns 12267.9999 


8. CUInt :- It converts given data value into CUint datatype . Here,  UInt stands for Unsigned integer type. Dim Double_Variable As Double  Dim aUInt_Variable As UInteger Double_Variable = 39.501 aUInt_Variable = CUInt(Double_Variable)

Msgbox ( aUInt_Variable )

'It Return 40

9. CShort :- It converts the given data value into short integer type
data value.

Syntax :- 
CShort ( Byte_Variable )

Example :-
Dim Byte_Variable As Byte 
Dim Short_Variable As Short
Byte_Variable = 100
Short_Variable = CShort(Byte_Variable)
Msgbox ( Short_Variable )

10. CDec :- It converts the given data value into Decimal Data-Type value.


Syntax :- CDec ( Variable_Name ) 
 
 
  Example :-
 
Dim Double_Variable As Double 
Dim Decimal_Variable As Decimal 
Double_Variable = 10000000.0587 
Decimal_Variable = CDec(Double_Variable) 
Msgbox ( Decinal_Variable )




No comments:

Post a Comment