VB data type

Source: Internet
Author: User
I. Data Type overview data: A computer can process numeric, text, sound, graphics, images, and other information, which is called data. Data Type: Based on the meaning of the data description, data is divided into different types, which are defined as data types. For different data types, the storage structure in the memory is also different, And the occupied space is also different from the basic data type of VB: numeric data (main data type) date byte type currency type logical string type object type variant 2. Numerical data type numeric types are classified into integer type and real number type. 1. The integer type refers to the number without decimal points and exponent symbols. The integer type in the specified range is divided into: integer, long integer (1) INTEGER (integer, type character %) the integer number occupies two bytes in the memory (16 digits) value range of a decimal INTEGER:-32768 ~ + 32767 For example: 15,-345,654% are all Integer type. In contrast, 45678% will cause an overflow error. (2) The long integer (long, type operator &) occupies 4 bytes (32 bits) in the memory ). Value range of long integer in decimal format:-2147483648 ~ + 2147483647 For example: 123456,45678 & all are long integers. 2. Real-number (floating-point or real-Number) Real-number data refers to the number with a decimal part. Note: Numbers 12 and 12.0 are different for computers. The former is an integer (two bytes) and the latter is a floating point number (four bytes) real-number data can be divided into floating-point numbers and fixed points. A floating point number consists of three parts: symbol, index, and ending number. In VB, floating point numbers are divided into two types: Single-precision floating point numbers (single) double-precision floating point numbers (double) (1) Single-precision number (single, type character !) Memory occupies 4 bytes (32-bit), valid number: 7-bit decimal number value range: Negative-3.402823e + 38 ~ -1.401298e-45 positive numbers 1.401298e-45 ~ 3.402823e + 38 there cannot be any top-down Mark writing in computer programs, therefore, the power multiplication is an expression called scientific notation. Here e or E is used to represent the power of 10 (E/E can both be case sensitive), for example: 1.401298e-45 indicates the negative 45 power of 10 of 1.401298. In VB, it can be represented as follows: 8.96e-5 example: 21e5 (the positive number is omitted) indicates: 21 multiplied by the power of 10 to a single precision (2) double (double, type character #) double data occupies 8 bytes in the memory (64-bit) the double type can be accurate to 15 or 16 decimal digits, that is, 15 or 16 valid digits. Value range: Negative. Values:-1.797693134862316d + 308 ~ -4.94065d-324 positive value: 4.94065d-324 ~ 1.797693134862316d + 308, for example, 17.88d5, indicates that it is a double-precision number, indicating that 17.88 is multiplied by 10 to the fifth power. Here, D is used to represent 10 to the second power and currency type (currency, type operator @) it is mainly used to indicate the currency value, which occupies 8 bytes (64 bits) in the memory. The integer part is 15 BITs, which can be precise to four decimal places and rounded to the fifth digit; the value range of the real currency data of the specified point:-922337203685447. 5808 ~ 922337203685447. The difference between 5807 and floating point: the digits after the decimal point are fixed. Four digits, for example, 3.56 @ and 65.123456 @, are currency-type. 3. bytes (byte, no type character) are generally used to store binary data. Byte data occupies 1 byte (8 bits) in the memory ). Value range of byte data: 0 ~ 255 4. Date occupies 8 bytes in memory and is stored as a floating point number. The date range of the date type data is from January 1, January 1, 100 ~ The time range of the date data for January 1, December 31, 9999 is: 00:00:00 ~ 23:59:59 is used to enclose the date and time, and various formats can be used to represent the date and time. Dates can be separated by "/", ","-", which can be year, month, day, or month, day, or year. Time must be separated by ":". The order is hour, minute, and second. Example: #09/10/2000 # Or #2000-09-12 #08:30:00 am #09/10/2000 08:30:00 am # example: dim mylab as date mylab = #9/3/2001 11:35:00 am # Time = mylab will be automatically converted to mm/DD/yy (month/day/year) in VB. 5. Logical (Boolean) Logical Data occupies 2 bytes in the memory. Logical Data has only two possible values: true (true) False (false) if the Logical Data is converted to a numeric value, true (true) is-1 false (false) 0. When numeric data is converted to boolean data, convert non-zero data to true and 0 to fasle. 6. String (string, type character $) a string is a character sequence and must be enclosed in double quotation marks. Double quotation marks are the delimiters and are not displayed during input and output. The number of characters in a string is called the string length. A string with zero length is called an empty string, such as "". No character contained in the string is case sensitive. Strings can be divided into variable-length strings and fixed-length strings. (1 ). for example, dim A as string a = "123" A = "456789" (2 ). for a fixed-length string (with a specified length), when the character length is lower than the specified length, it is filled with spaces. When the character length is greater than the specified length, the extra characters are truncated. Example: dim A as string * 10 7. Object Data occupies 4 bytes in memory. Used to reference objects in an application. 8. Variant data type (variant) the variant data type is a special data type with great flexibility and can represent multiple data types, the final type is determined by the value assigned to it. 9. User-defined types if I want to record a student's student ID, name, gender, and total score at the same time, I can use custom types. User-Defined type features: This type of data is composed of several different types of basic data. Custom types are implemented by the Type statement. Format: type custom type name element name 1 as type name element name 2 as type name ...... Element name N as type name end type is the statement Definition character, telling VB to define a data type now, is the keyword of VB; the custom type name is the name of the data type to be defined, determined by the user; end type indicates that the type definition ends; the custom type name is the name of the variable that makes up the data type. For example, type student num as long 'student ID name as string * 10' name, sex as string * 5' gender is stored with a fixed-length string of 10, and score as single is stored with a fixed-length string of 5, the end type stored with a single precision is generally defined in the standard module. If you only want to define it in the form, you must add private to the front to indicate that this type is only valid for this form, other forms cannot define variables of this type. After the student type is defined, we can define the variables of the student type, such as dim Stu as student.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.