difference between empty and NULL in a VBS _VBS

Source: Internet
Author: User
The empty keyword is used to indicate the value of an uninitialized variable, unlike null
Null keyword is used to indicate that the variable contains data that is not valid, unlike empty
Instance:
Dim p
Now
IsEmpty (p) is true
IsNull (p) is null
For example, a field that reads out a record in a database is null, and the field has no data
P=rs ("PPP")
At this point IsNull (p) =true
Talk about an easy fuzzy thing (maybe it's also a place for everyone to understand)
VBS uses variable assignment when no option Explicit is allowed without declaring a variable
If there is no dim p and direct
P= "AAA" will implicitly define the variable p the first time it is met, it may be confusing here,
-------------
One
Dim p
IsEmpty (p) is true
IsNull (p) to False
Display defines a variable
---------------
Second:
IsEmpty (p) is true
IsNull (p) to False
The program is not allowed to continue if the option Explicit is not forced to be declared
Implicitly defines the variable, and the implicit definition occurs the first time the variable is used
When you do not have an explicit Dim p, the first time you use P, you will actually run the mechanism ==>
IsEmpty (P)
(Search function scope, no definition, and then search the global scope, there is no definition!!) Ok first define Dim p)
and then
IsEmpty (P)
is actually
IsEmpty (P)
--->
(P? ----> No Dim p----> Dim P)
---->
IsEmpty (P)
IsNull (P)
So the processing result of the program IsNull (p) ==false instead of true
Null is not too good to catch it, how to judge him?
-------
P=null
IsNull (P) =true
Now strange, how p is initialized, and how IsNull (p) =true, because it happens when NULL is assigned to p, the p variable is used to represent nonexistent data.
More specifically, the word "Nothing" is now represented by P.
--------
When will the IsNull be true?
For example, when database object data calls occur, the columns of the database allow null
(What's worse!!) The Chinese translation of the SQL server2000 null at this time also called "null value", confused, all the reasons for the translation, so to be more use, to understand the real difference between empty,null, do not confuse the translation of Chinese characters, and different languages on null There are some differences in the processing of empty)
"Vacuum" can be called empty.
And Null doesn't even have a "vacuum".
This is in itself two very abstract concepts!!
Give another example to deepen the understanding of null and empty
There are two tables below, a table has three records, all have actual data, B table has two records, second record "b Field 1"
is a null character; the AID BID of table A and table B are automatically numbered fields, no padding null is allowed
Table A | Table B
__________________ |________________________________
AID a Field | BID b Field
1 AAA1 | 1 BBB1
2 AAA2 | 2
3 AAA3 |
___________________________________________________
The result of a left outer Join B defined by aid and bid
(SELECT * from A LEFT join B on A.aid=b.bid)
___________________________________________________
AID a field 1 BID B Field 1
1 AAA1 1 BBB1
2 AAA2 2
2 AAA2 3 Null
___________________________________________________
Analyze the results above:
A LEFT JOIN B is mandatory B table matching a table output recordset, regardless of B table bid exists in a table!
In this way, the bid=1 bid=2 of B table matches the aid=1 aid=2 of a, so the corresponding data of bid appear in the result set.
The record number bid=3 in table B does not exist, there is a requirement to force matching into the federated result set, at this time, based on the conditions on A.aid=b.bid, the b.bid=a.aid appears in the B table of the union output columns, and "b Field 1" of the
The third record does not exist, at which point the federated result set can only be data that is identified as null---//non-existent
and the blank character of record 2 continues to be populated as a null character symbol
In this example cough a see the true meaning of NULL use
The null character in the data is equivalent to having an empty seat
and null, not even this empty seat.
Another example:
1:AAA 2:bbb 3:4:dd ' 3: The place is empty
1:AAA 2:bbb 4:dd ' The seat number 3: None, there is a null

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.