Changes

String Functions and Manipulation in VB6

2,642 bytes added, 22:46, 15 February 2008
/* Null, 0, and Empty Strings */
The following lines were added (+) and removed (-):
vbNullString: The same as "", as in an empty string.  It is more efficient to use vbNullString though. use it instead of ""In VB, Null is a subtype of a Variant, in the same way the Empty is also. In other words, Null and Empty are both special states of a Variant variable.vbNull: This is supposed to be NULL but actually equals 1.vbNull and vbEmpty are the codes returned from the VarType function when applied to a value of that type, e.g.     VarType(Empty) = vbEmpty    VarType(Null) = vbNull This provides one method of testing whether a value is Null or Empty. The other is by calling the IsNull and IsEmpty functions. In a database, NULL has a similar status to Null is VB Variants, althoughit's defined by the SQL standard rather than the VB language. Use the NULL keyword to assign Null to a recordset field, use the IsNull function to test if a recordset fields contains Null. * '''vbNullString''': The same as "", as in an empty string.  It is more efficient to use vbNullString though.  use it instead of "" * '''vbNull''': This is supposed to be NULL but actually equals 1. * '''vbNullChar''':  * '''Null''': Used for writing NULL, however, will appear as a 0 in a database numeric field after write. * '''Empty''': Also appears as a 0 in a database numeric field after write. * '''Nothing''':  === The Differences among Empty, Nothing, vbNull, vbNullChar, vbNullString and the Zero-Length String === quoted from somewhere:   '''""''': A zero-length string (commonly called an "empty string") is technically a zero-length BSTR that actually uses six bytes of memory. In general, you should use the constant vbNullString instead, particularly when calling external DLL procedures. '''Empty''': A variant of VarType 0 (vbEmpty) that has not yet been initialized. Test whether it is "nil" using the IsEmpty function. '''Nothing''': Destroys an object reference using the Set statement. Test whether it is "nil" using the Is operator: If obj Is Nothing Then... '''Null''': A variant of VarType 1 (vbNull) that means "no valid data" and generally indicates a database field with no value. Don't confuse this with a C NULL, which indicates zero. Test whether it is "nil" using the IsNull function. '''vbNullChar''': A character having a value of zero. It is commonly used for adding a C NULL to a string or for filling a fixed-length string with zeroes: Path = String(255, vbNullChar) '''vbNullString''': A string having a value of zero, such as a C NULL, that takes no memory. Use this string for calling external procedures looking for a null pointer to a string. To distinguish between vbNullString and "", use the VBA StrPtr function: StrPtr(vbNullString) is zero, while StrPtr("") is a nonzero memory address. [Note: the StrPtr() function may not be a part of the VBA members shown in the Object Browser so it will not AutoComplete. Enter the following line in the Immediate Window to determine if this function is available: ?StrPtr(vbNullString). This should return 0 immediately.]vbNullChar:
Bureaucrat, administrator
16,192
edits