Convert
This module can be used to convert numbers into string representation of numbers or vice versa.
Hex
Function Hex(value As varType) As String
Function Hex(value As varType, padCount As Byte, Optional padChar As Char = "0") As String
- value - The number to convert. The argument can be of type Byte, SByte, UShort, Short, UInteger or Integer
- padCount- An optional parameter which will pack the left hand side of the returned string with padCount - length of character zeros.
- padChar- An optional parameter which changes the default packing character of "0" (zero).
This function will convert a number and return a hexadecimal string representation of the number passed. Optional padCount and padChar arguments can be used to format the returned string value. For example:
dim myString as string = Hex(128) ' result is "80" dim myString as string = Hex(128,4) ' result is "0080" dim myString as string = Hex(128,4,"#") ' result is "##80"
Oct
Function Oct(value As varType) As String Function Oct(value As varType, padCount As Byte, Optional padChar As Char = "0") As String
- value - The number to convert. The argument can be of type Byte, SByte, UShort, Short, UInteger or Integer
- padCount- An optional parameter which will pack the left hand side of the returned string with padCount - length of character zeros.
- padChar- An optional parameter which changes the default packing character of "0" (zero).
This function will convert a number and return an octal string representation of the number passed. Optional padCount and padChar arguments can be used to format the returned string value. For example:
dim myString as string = Oct(8) ' result is "10" dim myString as string = Oct(8,4) ' result is "0010" dim myString as string = Oct(8,4,"#") ' result is "##10"
Bin
Function Bin(value As varType) As String Function Bin(value As varType, padCount As Byte, Optional padChar As Char = "0") As String
- value - The number to convert. The argument can be of type Byte, SByte, UShort, Short, UInteger or Integer
- padCount- An optional parameter which will pack the left hand side of the returned string with padCount - length of character zeros.
- padChar- An optional parameter which changes the default packing character of "0" (zero).
This function will convert a number and return an binary string representation of the number passed. Optional padCount and padChar arguments can be used to format the returned string value. For example:
dim myString as string = Bin(15) ' result is "1111" dim myString as string = Bin(15,8) ' result is "00001111" dim myString as string = Bin(15,8,"#") ' result is "####1111"
Val
Function Val(value As String) As Integer
- value - The string number to convert.
This function will convert a string representation of a decimal integer number into an integer type. For example,
dim value as byte = val("123") ' result = 123
Str
Function Str(value As varType) As String Function Str(value As varType, padCount As Byte, Optional padChar As Char = "0") As String
- value - The number to convert. The argument can be of type Byte, SByte, UShort, Short, UInteger or Integer
- padCount- An optional parameter which will pack the left hand side of the returned string with padCount - length of character zeros.
- padChar- An optional parameter which changes the default packing character of "0" (zero).
This function will convert a number and return an decimal string representation of the number passed. Optional padCount and padChar arguments can be used to format the returned string value. For example:
dim myString as string = Str(123) ' result is "123" dim myString as string = Str(123,4) ' result is "0123" dim myString as string = Str(123,4,"#") ' result is "#123"