lukieleetronic
lukieleetronic

Reputation: 623

VBA Variant Array - test for empty is not working with integer value of 0

I've got the following VBA code Extract,

Dim ERA_Curves AS Variant
ReDim ERA_Curves(2000,19)

ERA_Curves (350,4) = 0

then when I test for

ERA_Curves(350,4) <> Empty 

it returns 'False'

Doesn't it suppose to return True since its got some value in the memory? I want to test if the memory is truly empty, (not assigned with any type value) am I missing something here?

Upvotes: 0

Views: 1516

Answers (1)

barrowc
barrowc

Reputation: 10679

You need the IsEmpty function - used like this:

If IsEmpty(ERA_Curves(350, 4)) Then

Comparing things to Empty with <, > etc doesn't work but you can assign Empty directly to a Variant if you want to:

ERA_Curves(350, 4) = 0

If IsEmpty(ERA_Curves(350, 4)) Then
    MsgBox "empty"
Else
    MsgBox "not empty"
End If

ERA_Curves(350, 4) = Empty

If IsEmpty(ERA_Curves(350, 4)) Then
    MsgBox "empty"
Else
    MsgBox "not empty"
End If

Upvotes: 2

Related Questions