isNull(control.selectedValue) or isEmpty(control.selectedValue)?

I have a macro to only perform certain tasks if a listbox control has a value selected. It uses:

If not isEmpty(oMeasDataControl.selectedValue) and not isNull(oMeasDataControl.selectedValue) Then

I suspect i don’t need to check both that it isn’t null and that it isn’t empty, and I’m doing some cleanup. What’s the difference between the two checks?

Why this question? Why can’t you find out the the difference between a control with and without selected value? You have all the tools at hand.

IsEmpty tests if a Variant is not initialized at all. It is true when you have just created a variable like in

Dim x ’ Variant by default
MsgBox IsEmpty(x)

IsNull is for object variables. Its behavior differs in VBA and in StarBasic. In former, it is only true when the value of object variable is equal to a special Null value. In StarBasic, it is also true when the object variable is empty (but it is not for other kinds of empty variables other than object).

Basically, you likely need both checks, because none of them covers all cases.

2 Likes

you could use this:

if ubound(oMeasDataControl.selecteditems()) <> -1 then