VB6 Tutorial 39: Data Inspection Functions

By | 2018-04-23

You’ll learn about some data inspection functions in this lesson. These functions will inspect the expression. More precisely, these functions will provide you the information related to your expression. You’ll get these functions in the Object Browser inside the “Information” module.

In this lesson, we’ll be learning about the following functions:

  • IsNumeric
  • IsArray
  • IsDate
  • IsEmpty
  • IsObject
  • TypeName
  • IsError
  • IsMissing
  • IsNull

IsNumeric

The IsNumeric function returns Boolean value, returns True if an expression can be evaluated to a number.

This function is useful when you want your users to enter only the numeric values in the required field.

Example

Private Sub cmdCheck_Click()
    If IsNumeric(txtField.Text) = True Then
        MsgBox "Value accepted"
    Else
        MsgBox "Please enter a numeric value"
    End If
End Sub

IsArray

The IsArray function returns a Boolean value, returns True if the variable is an array. When you want to check whether a particular variable is an array, the IsArray function is useful.

Example

Dim team(20) As Integer
If IsArray(team) = True Then
    MsgBox "This is an array"
Else
    MsgBox "This is NOT an array"
End If

IsDate

The IsDate function returns a boolean value, returns True if an expression is a date.

Example

Dim dt As Date

dt = 20 / 20 / 2013

If IsDate(dt) = True Then
    MsgBox "This is a date"
Else
    MsgBox "This is NOT a date"
End If

IsEmpty

The IsEmpty function returns True if a variable has not been initialized.

Example

Take a variant variable score.

If IsEmpty(score) = True Then
        MsgBox "Not initialized"
    Else
        MsgBox "Initialized"
End If

IsObject

The IsObject function returns True if the variable is of Object type.

Example

Dim frm As Form
 
If IsObject(frm) = True Then
    MsgBox "Object variable"
Else
    MsgBox "This is NOT an object variable"
End If

TypeName

Returns the datatype of the variable.

Example

Dim n As Integer
n = 34
Dim str As String
str = TypeName(n)
MsgBox str

IsError

Returns True if an expression is an error value.

IsMissing

Returns True if an optional argument has not been passed.

IsNull

Returns True if an expression doesn’t contain any valid data.

Related topics

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.