Data: Computers can handle information such as numerical values, words, sounds, graphics and images, which are called data.
Data type: according to the meaning of data description information, data is divided into different types, and the classification of data types is stipulated, which is called data type. Different data types have different storage structures and occupy different memory space.
Basic data types of VB:
Digital Data (Primary Data Type) Date Byte Type
Currency logic string object variable
Second, the numerical data type.
Numerical types are divided into integer type and real number type.
1, integer type
Integer types refer to numbers without decimal points and exponential symbols.
According to the integer type of expression range, it can be divided into integer type and long integer type.
(1) integer (type symbol%)
Integer occupies two bytes (16 bits) in memory.
The range of decimal integers is -32768 ~ +32767.
For example, 15, -345 and 654% are all integer types. And 45678% will have overflow errors.
(2) Long (type symbol &; )
Long integers occupy 4 bytes (32 bits) in memory.
Value range of decimal long integer:
-2 147483648 ~ +2 147483647
For example:123456,45678 &; Are all long integers.
2. Real number (floating point number or real number)
Real data refers to numbers with decimal parts.
Note: The number 12 and the number 12.0 of the computer are different. The former is an integer (accounting for 2 bytes) and the latter is a floating-point number (accounting for 4 bytes).
Real number data is divided into floating point number and fixed point number.
Floating-point number consists of three parts: symbol, exponent and mantissa.
There are two floating-point numbers in VB:
Single precision floating-point number (single)
Double precision floating-point number
(1) single-precision number (single precision, type symbol! )
It occupies 4 bytes (32 bits) of memory, and the effective digits are 7 decimal digits.
Value range: negative number-3.402823e+38 ~-1.401298e-45.
Positive number1.401298e-45 ~ 3.423e+38.
There can't be superscript and subscript writing in computer programs, so a method called scientific counting is used to represent power.
Here, e or e is used to represent the power of 10 (E/e can be capitalized).
For example, 1.40 1298E-45 means that 1.40 1298 is the negative 45th power of 10.
In vb, it can be expressed as: 8.96E-5.
For example: 2 1e5 (omit the plus sign) means:
2 1 times 10 to the fifth power is a single precision number.
(2) Double (type symbol #)
Double-precision data occupies 8 bytes (64 bits) in memory.
Double can be accurate to 15 or 16 decimal places, that is, 15 or 16 significant digits.
Value range:
Negative numbers:–1.796931348 62316d+308 ~-4.94065d-324.
Positive numbers: 4.94065d-324 ~1.7913486216d+308.
For example, 17.88D5 represents a double precision number, that is, 17.88 times 10 to the fifth power.
Here d is used to represent the power of 10.
II. Currency (currency, type symbol @)
Mainly used to represent monetary value, accounting for 8 bytes (64 bits) in memory;
The integer part is 15 digits, which can be accurate to four decimal places, and the fifth digit is rounded off; Belong to fixed-point real number
Value range of currency data:
-922337203685447.5808 ~ 922337203685447.5807
Difference from floating-point number: the number of digits after decimal point is fixed, 4 digits.
For example: 3.56 @ 65. 123456 @ are all currencies.
Three, byte type (bytes, no type symbol)
Generally used to store binary numbers.
Byte data accounts for 1 byte (8 bits) in memory.
Value range of byte data: 0 ~ 255.
Fourth, the Date type (date)
It occupies 8 bytes in memory and is stored as a floating-point number.
The date expression range of date data is:
000 65438+65438+ 10/~ 999 65438+365438+February 0.
The time expression range of date data is:
00:00:00 ~ 23:59:59
Enclose the date and time with #, and allow various formats to represent the date and time.
Dates can be separated by "/","and"-",which can be year, month and day, or the order of month, day and year. Time must be separated by ":",and 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:
Show my tags as dates
mylab = # 9/3/2006 54 38+0 1 1:35:00AM #
Time = mylab
It will be automatically converted into mm/dd/yy (month/day/year) in VB.
Verb (abbreviation for verb) Logical type (Boolean type)
Logical data occupies 2 bytes in memory.
Logical data has only two possible values:
True (true) false (false)
If logical data is converted into digital data, then:
True is-1false is 0.
When digital data is converted into Boolean data:
Non-zero data is converted to true and 0 is fasle.
Six, string (string, type symbol $)
A string is a series of characters and must be enclosed in double quotation marks.
Description:
Double quotation marks are delimiters and are not displayed during input and output.
The number of characters contained in a string is called the string length.
A zero-length string is called an empty string, such as "",and there is nothing in the quotation marks.
Characters contained in a string are case-sensitive.
String can be divided into variable-length string and fixed-length string.
(1). Variable-length string (length is the length of the string)
Example: darken a as a string
a=" 123" a="456789 "
(2). Fixed-length string (the length is the specified length)
For fixed-length strings, when the character length is less than the specified length, it is filled with spaces, and when the character length is greater than the specified length, the redundant characters are truncated.
Example: Mark A as a string * 10.
Seven, Object data type (object)
Object-oriented data occupies 4 bytes in memory. Used to refer to objects in an application.
Eight, variable data type (Variant)
Variant data type is a special data type, which has great flexibility and can represent many data types, and its final type is determined by the value given to it.
Nine, user-defined types
If I want to record a student's student number, name, gender and total score at the same time, then I can use a custom type.
Custom Type Features: This type of data consists of several different types of basic data.
The custom type is realized by the type statement:
Format: Type Custom Type Name
Element name 1 as the type name.
Element name 2 as the type name.
……
Element name n as the type name.
End type
Type is a statement definer, telling vb to define a data type now, which is the keyword of VB; The following user-defined type name is the name of the data type to be defined, which is determined by the user; The end type indicates the end of the type definition; The custom type name is the name of the variable that makes up the data type.
Example:
Student type
"Num as long" student number
The name is string * 10' name, which is stored by a fixed-length string with the length of 10.
Sex as string * 5' gender, stored by a fixed-length string with a length of 5.
The score of "Single Score" is stored as a single precision number.
End type
Generally defined in the standard module, if you only want to define it in a form, you must add Private in front, indicating that this type is only valid for this form, and other forms cannot define variables of this type.
After defining the student type, we can define the variables of the student type, such as: Dim Stu As Student.