Is functions
An editor has nominated this article for deletion. You are welcome to participate in the deletion discussion, which will decide whether or not to retain it. |
Function name | VB 6 | VBA | VBScript | VB .NET | T-SQL |
---|---|---|---|---|---|
IsArray |
? | ? | Yes | Yes | No |
IsDate |
Yes | Yes | Yes | Yes | Yes |
IsDBNull |
No | ? | No | Yes | No |
IsEmpty |
Yes | ? | Yes | No | No |
IsError |
? | ? | No | Yes | No |
IsMissing |
Yes | ? | No | No | No |
IsNothing |
? | ? | No | Yes | No |
IsNull |
Yes | ? | Yes | No | Yes |
IsNumeric |
Yes | Yes | Yes | Yes | Yes |
IsObject |
? | ? | Yes | No | No |
IsReference |
? | ? | No | Yes | No |
The Is
functions (also known as data information functions[1], data inspection functions[2], or data-testing functions[2]) are a set of functions in Microsoft's Visual Basic 6, Visual Basic for Applications, VBScript, and Visual Basic .NET. Several of them are also provided in Transact-SQL by the .NET Framework Data Provider for Microsoft SQL Server.
What the functions do
The functions are simple data validation and data type checking functions. The data validation functions determine whether it is possible to convert or coerce the data value given as an argument to the function to the type implied by the function name, and return a Boolean
value recording whether it was possible or not. (Note that the actual data conversion functions, such as Oct()
throw exceptions if conversion is not possible. The validation functions allow one to test whether a conversion would fail, and change the program's flow of control in an if statement.) True
indicates that conversion would be possible, False
indicates that it would not be. Similarly the type checking functions return a Boolean
recording whether the argument expression is of a particular type.
In Transact-SQL, the functions return zero or one rather than Boolean
values True
and False
.
IsArray(name)
- This function determines whether the variable name passed as its argument is an array. Uninitialized arrays will, note, return
False
from this function.[3] IsDate(expression)
- This function determines whether the expression passed as its argument can be converted to a variable of type
Date
, or is already of typeDate
. Uninitialized variables that are of typeDate
can of course be converted, despite being uninitialized, so this will always returnTrue
for such variables.[4] Note that strings that contain a day of the week in addition to a date (e.g."Sat, October 12, 2010"
) will return a failure result.[5] In VBScript, the conversion process employs the locale settings of Microsoft Windows, meaning that what may parse as a date on one system, configured to use one locale, may fail to parse as a date on another system, configured to use a different locale.[6] IsDBNull(expression)
- This function determines whether the expression passed as its argument evaluates to
System.DBNull.Value
.[4] This is equivalent to Visual Basic 6'sIsNull()
function.[5] IsEmpty(expression)
- This function determines whether the expression passed as its argument is an uninitialized variant. Note that an uninitialized variant is distinct from a variant that has been initialized to hold
Null
.[7] Although the function takes an expression, rather than simply a variable name, any expression that isn't simply a variable name is considered not to be an uninitialized variant.[6] This function, available in Visual Basic 6, is not available in Visual Basic .NET., and is superceded by theIsNothing()
function.[8] In VBScript, if a variant is assignedNothing
, this function still returnsFalse
.[9] IsError(expression)
- This function determines whether the expression passed as its argument is an exception object, i.e. an object of the
System.Exception
class or one of its subclasses.[3] IsMissing(name)
- This function determines whether the variable name passed as its argument is an optional argument that was not passed to a function by its caller. It returns
True
only of the variable is a variant that has not been initialized. This function only exists in Visual Basic 6. In Visual Basic .NET, optional parameters are required to have default initializers, and the function no longer exists.[10] IsNothing(expression)
- This function determines whether the expression passed as its argument evaluates to
Nothing
.[4] IsNull(expression)
- This function determines whether the expression passed as its argument evaluates to
Null
. A null value in any sub-expression of the expression causes the entire expression to be considered null.[9] IsNull(expression1,expression2)
- This function, taking two arguments, is specific to Transact-SQL. In contrast to the Visual Basic function by this name, it does not return a
Boolean
, but instead returns the first expression if that is notNULL
, otherwise the second expression.[11] The purpose of the function is to replace anyNULL
values with another, presumably (but not required to be) non-NULL
, value.[12] It is a two-argument version ofCOALESCE()
. IsNumeric(expression)
- This function determines whether the expression passed as its argument can be converted to a number (be that a
Short
,Integer
,Long
,Single
,Double
, orDecimal
) from a character or string, or is already a number.[13][14] In Transact-SQL, strings can be converted to numbers even if they contain characters that one might not expect in numbers. This is because Transact-SQL allows conversion frommoney
andsmallmoney
types to numbers, and monetary data in string form may contain currency indicator characters such as the '£
' or '$
' symbols.[15] The same is true of VBScript, where any string that can be converted to a currency value in the current locale is considered to be numeric. VBScript does not, however, consider dates and times to be numeric.[16] IsReference(expression)
- This function determines whether the expression passed as its argument is a reference rather than a value.[13] This is equivalent to Visual Basic 6's
IsObject()
function.[5]
References
What supports what
- ^ Harris 1999, p. 402.
- ^ a b Perry & Hettihewa 1998, p. 237.
- ^ a b Roman, Petrusha & Lomax 2002, p. 69.
- ^ a b c Roman, Petrusha & Lomax 2002, p. 86.
- ^ a b c Petroutsos 2002, p. 115.
- ^ a b Lomax, Childs & Petrusha 2003, p. 341.
- ^ Harris 1999, p. 416.
- ^ Wakefield & Sonder 2001, p. 690.
- ^ a b Lomax, Childs & Petrusha 2003, p. 342.
- ^ Petrusha 2006, p. 367,528,637.
- ^ Israel & Jones 2001, p. 476.
- ^ Price 2003, p. 119.
- ^ a b Roman, Petrusha & Lomax 2002, p. 87.
- ^ Petroutsos 2002, p. 114.
- ^ MSDN & 1.
- ^ Lomax, Childs & Petrusha 2003, p. 343.
Sources used
- Harris, Matthew (1999). Sams teach yourself Microsoft Excel 2000 programming in 21 days. Sams Teach Yourself Series. Sams. ISBN 9780672315435.
{{cite book}}
: Invalid|ref=harv
(help) - Israel, Marc; Jones, J. Steven (2001). MCSE: SQL Server 2000 design study guide. Certification Study Guide Series. John Wiley and Sons. ISBN 9780782129427.
{{cite book}}
: Invalid|ref=harv
(help) - Lomax, Paul; Childs, Matt; Petrusha, Ronald (2003). VBScript in a nutshell. In a Nutshell (2nd ed.). O'Reilly Media, Inc. ISBN 9780596004880.
{{cite book}}
: Invalid|ref=harv
(help) - Perry, Greg M.; Hettihewa, Sanjaya (1998). Sams teach yourself Visual Basic 6 in 24 hours. Teach Yourself in 24 Hours Series (2nd ed.). Sams Publishing. ISBN 9780672315336.
{{cite book}}
: Invalid|ref=harv
(help) - Petroutsos, Evangelos (2002). Mastering Visual Basic.NET. Mastering Series. John Wiley and Sons. ISBN 9780782128772.
{{cite book}}
: Invalid|ref=harv
(help) - Petrusha, Ronald (2006). Visual Basic 2005: the complete reference. McGraw-Hill Professional. ISBN 9780072260335.
{{cite book}}
: Invalid|ref=harv
(help) - Price, Jason (2003). Mastering C# database programming. John Wiley and Sons. ISBN 9780782141832.
{{cite book}}
: Invalid|ref=harv
(help) - Roman, Steven; Petrusha, Ron; Lomax, Paul (2002). VB.NET Language Pocket Reference. O'Reilly Media, Inc. ISBN 9780596004286.
{{cite book}}
: Invalid|ref=harv
(help) - Wakefield, Cameron; Sonder, Henk-Evert (2001). Lee, Wei Meng (ed.). VB.net Web developer's guide. Syngress. ISBN 9781928994480.
{{cite book}}
: Invalid|ref=harv
(help) - "ISNUMERIC (Transact-SQL)". MSDN: SQL Server 2008: Transact-SQL Reference. Microsoft.
Further reading
Microsoft's on-line documentation
- "
IsArray
method". MSDN: .NET Framework Class Library:Microsoft.VisualBasic
namespace. Microsoft. - "
IsDate
method". MSDN: .NET Framework Class Library:Microsoft.VisualBasic
namespace. Microsoft. - "
IsDBNull
method". MSDN: .NET Framework Class Library:Microsoft.VisualBasic
namespace. Microsoft. - "
IsError
method". MSDN: .NET Framework Class Library:Microsoft.VisualBasic
namespace. Microsoft. - "
IsNothing
method". MSDN: .NET Framework Class Library:Microsoft.VisualBasic
namespace. Microsoft. - "
IsNumeric
method". MSDN: .NET Framework Class Library:Microsoft.VisualBasic
namespace. Microsoft. - "
IsReference
method". MSDN: .NET Framework Class Library:Microsoft.VisualBasic
namespace. Microsoft.
Other
This article has not been added to any content categories. Please help out by adding categories to it so that it can be listed with similar articles. (January 2011) |