VB6 checks if a variable is an object

In Visual Basic 6, is there anyway to indicate whether the variable passed to the function is an object? I want to be able to check if a variable is null, nothing, or empty, but only objects can be tested using Nothing. Any ideas?

+4
source share
4 answers

How is a function defined?

If it is ... As Object , then it is either a valid object or Null .

If it's ... As Variant (or not type), then everything can be passed, and you can check with IsEmpty() , IsNull() (Note, NOT a null object, but a null value) or IsObject() depending on of what exactly you want to check before checking ... Is Nothing .

If the parameter is Optional , you can use IsMissing() , but it must be a variant type without a default value.

Also, check out this article about the various uses of Null in VB.

+6
source
 IsObject(variable) 

Not hard to find

+4
source

VB has a TypeOf . Everything that is not a simple value (i.e. Integer, etc.), Has an Object type.

 If TypeOf Variable Is Object Then ' ... End If 

TypeOf also allows for inheritance checks. For example, the mail items in the Outlook folder are Object and Outlook.MailItem types, so you can perform actual type checks for the generic variale in this way.

Please note that If TypeOf ... does not work with variables that are entered as simple values ​​(i.e. Integer), only with object type variables (Variant, COM objects, built-in objects).

+1
source

For Variant arguments, you can also use the VarType () function and the associated Enum function.

0
source

Source: https://habr.com/ru/post/1381925/


All Articles