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 :-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 )Dim DateString As String Dim Finl_Date As Date DateString = "July 3, 2013"'The following line converts date format given in Date Type and giveit to Finl_DateFinl_Date = CDate ( aDateString )Msgbox ( Finl_Date.tostring())4. CDbl :- CDbl stands for Convert to Double Data-Type. It convertsthe any given integer value to Double floating value5. CInt :- CInt Stands for Convert to Integer Date -Type . CInt iswidely 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 206. CChar :- CChar Stands for Convert to character. It Takes a StringVariable as input Argument and as it convert it into char so it passesthe first character of specified string varible to a charactervariableSyntax :-CChar ( String_Variable )Example :-Dim String_variable As String = "bvf"Dim char_variable As Charchar_variable = CChar(String_variable) MsgBox ( char_variable )7. Cstr :- Cstr stands for convert to string . It converts anyinteger floating value given as input to CStr into string type valueSyntax :-Cstr ( Variable_Name )Example :-Dim Str as StringDim input as integerinput = 12267.9999Str = Cstr ( input )Msgbox ( Str )' It Returns 12267.99998. 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 409. CShort :- It converts the given data value into short integer typedata value.Syntax :-CShort ( Byte_Variable )Example :-Dim Byte_Variable As ByteDim Short_Variable As ShortByte_Variable = 100Short_Variable = CShort(Byte_Variable)Msgbox ( Short_Variable )10. CDec :- It converts the given data value into Decimal Data-Typevalue.Syntax :-CDec ( Variable_Name )Example :-Dim Double_Variable As DoubleDim Decimal_Variable As DecimalDouble_Variable = 10000000.0587Decimal_Variable = CDec(Double_Variable)Msgbox ( Decinal_Variable )
Tuesday, 2 July 2013
Conversion Functions VB.NET
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment