This topic is now archived and is closed to further replies.

Checking for objects set to nothing in VB

This topic is 6565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is a VB only question.

If I've got a function that has an Optional parameter (a class), how do I check if it's passed or not? The IsMissing() function doesn't seem to work on classes.

Share this post

Link to post
Share on other sites
Use a structure like this:


Private Sub Something(Optional clsParam As clsTest)

If clsParam Is Nothing Then
MsgBox "Missing parameter"
MsgBox "Parameter passed"
End If

End Sub

This assumes that the class you're passing has been initialized.

IsMissing only works for optional variants, which is rarely used now that optional parameters can be any data type. This is probably a carryover from VB4 when optional parameters had to be variants.

Breakaway Games

Share this post

Link to post
Share on other sites