Checking for objects set to nothing in VB

Started by
0 comments, last by Spiff 24 years, 3 months ago
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.

============================Daniel Netz, Sentinel Design"I'm not stupid, I'm from Sweden" - Unknown
Advertisement
Use a structure like this:

code:
Private Sub Something(Optional clsParam As clsTest)    If clsParam Is Nothing Then        MsgBox "Missing parameter"    Else        MsgBox "Parameter passed"    End IfEnd 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

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

This topic is closed to new replies.

Advertisement