Mitsules, Mark S. (Newport News)
Mark.Mitsules at ngc.com
Wed Jan 21 11:44:30 CST 2004
Gustav, There is a very short discussion of "When is Nothing something?" here: http://www.vbdesign.net/expresso/archive/topic/3244.html Mark =================== When is Nothing something? One of the most important elements of VBA, as a language, is its ability to detect nothing! There are many different nothings, and some of them are something, and as a rule they are not interchangeable. Lets take a look at assigning and checking nothing... ************* vbEmpty: Determines if a variable has been initialized - If varVariable = vbEmpty Then You should not use vbEmpty to make your variable nothing, because it makes it something! The value you are assigning is 0 (or if it is a string variable, "0") and the IsEmpty test will fail! ************ vbNull This one is great for testing for Null in a variable (database users take note) using VarType: If VarType (varVariable) = vbNull Then again, don't use this constant to try to assign a Null value, because its not nothing.. True value of vbNull is 1 (in a string variable "1") ************ vbNullChar Test for, or assign, a NullChar What is a Null char? The same thing as Chr(0). This one is great for working with the API when you need to pass a string that ends with a Null character, just add the constant onto the end of the string you are going to pass.. strVariable = strVariable & vbNullChar ************ vbNullString Test for, or assign, a null string I use this one all of the time for the API. It is the same thing as this: strVariable = "" You can see it in much of the code when I am looking for the Hwnd of a window using FindWindow lngHwnd = FindWindow(vbNullstring, Me.Caption) *********** Nothing For objects only - determines if the variable has a valid object reference or used to destroy the current object reference If objVariable Is Not Nothing Then objVariable = Nothing End If ********** Null Saved this one for last because it can confuse your code. Null assigns a Null value to your variant type variable, and you can use it to test for a Null value using IsNull, but because Null = false, a test like this varVariable = Null If varVariable = Null Then MsgBox "Its Null" End If will never show the message! Instead use this: If IsNull(varVariable) Then MsgBox "Its Null" End If and as a final not about nothing, don't try to use the Null keyword on strongly typed variables, if you do you will get the error "Invalid use of Null" -----Original Message----- From: Gustav Brock [mailto:gustav at cactus.dk] Sent: Wednesday, January 21, 2004 12:22 PM To: Access Developers discussion and problem solving Subject: [AccessD] vbNull = 1 Hi all Why does the VB constant vbNull equal 1 and not 0 (zero)? /gustav _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com