In VB, a lot of data type conversion is provided, especially the conversion functions of various credit data, and a string and digital conversion function, this article will make these functions a simple summary.
1. Various credited conversion functions The data entries include decimal, binary, and hexadecimal. Decimal is the data for our daily lives, so we are also our most familiar and clear; binary is the foundation of computers System, mainly because it is convenient to implement binary; octal and hexadecimal because of the native intimacy relationship, and it is more convenient than binary, therefore also become a common representation of the computer.
The conversion function between the data into the data involved in the VB mainly has the following: HEX function: returns a string of the hexadecimal value; Oct function: Returns a variant (string) of the eight-input value representing a value; CINT function : Forced an expression to convert an expression into -32, 768 to 32, 767; CLNG function: Force a long integer of -2, 147, 483, 648 to 2, 147, 483, 647; CDEC function: Forced an expression into a Decimal data type; CDBL Function: Forced to convert an expression into a Double data type;
These functions are the transition functions between the most basic data entries, where the previous three functions are most common, most useful. We can see from above, we can see that VB does not provide us with specialized functions We convert expressions or data into decimal and binary, but Ten-based conversions can be easily completed through the CINT function, and the binary implementation can be easily converted by binary and eight-year relationship.
The following examples are the HEX function and the OCT function and an instance of the CINT function: (1). A = HEX (5) Returns 5; (2). B = HEX (10) Returns A (3). C = HEX (23 Returns 17 (4). D = OCT (5) Returns 5 (5). E = OCT (10) Returns 12 (6). F = OCT (23) Returns 27 (7). G = CINT (& H17) Return 23 (8). H = CINT (& O12) Returns 10
The application of these functions is relatively simple, not to say, it is worth mentioning that the HEX function and the OCT function return are strings. If you want to convert hexadecimal or an octal string variable into a decimal, You can perform as follows: c = "17" 17 String c = "& h" & c ic = cint (c) returns 23
2. The string and digital conversion function VB are more convenient, it is more convenient, it will be introduced. This article mainly makes some summary of the conversion function related to the string. The string transformation function is mainly: STR () And VAL () for the mutual conversion of strings and numbers; chr () and ASC () used for mutual conversion of strings and ASCII codes; ChRW () and ASCW () for Unicode and Chinese mutual conversion The Format () function is a wide range of functions, which is very powerful.
The first two pairs of and format () functions in these functions are often used, only a few simple examples of the first two pairs: (1) MyString = STR (-459.65) 'Returns "-459.65". MyString = STR (459.001) 'Returns "459.001". (2) MyValue = VAL ("2 45 7") 'Returns 2457. MyValue = VAL ("24 and 57") 'returns 24. (3) MyChar = chr (97) 'Returns a. Mychar = chr (37) 'returns%. (4) MyNumber = ASC ("Apple") 'Returns 65. MyNumber = ASC ("a") 'Returns 97.