1
If IsArray(payCsv(pay_id)) = False Then
    'create tempArray
    lc = 0
    Debug.Print "create array"
End If

If IsArray(payCsv(pay_id)) = True Then
    Debug.Print " array exists, we should be able to get ubound"
    lc = UBound(payCsv(0)) - LBound(payCsv(0))
    l = l + 1
End If

I am using the above code to determine whether I can use Ubound on my 2D array (i.e. if the 2nd dimension is created, get length (ubound - lbound).

However, I am getting a compile error, even though condition 2 is false, it does not recognise that the code will not be relevant.

I am testing one array and the result is if I comment out "lc = UBound(payCsv(0)) - LBound(payCsv(0))" is "create array".

If I leave this line in there, I get the error "compile error - expected array"

Is this a bug in VBA?

1 Answer 1

3

If you want to access the UBound of the 2nd dimension of an array, the format goes like this:

UBound(payCSV, 2)

The MSDN page on this function may be helpful.

When you access payCSV(0) as you currently are, the code assumes that you want the 1st element within the 1st dimension of the payCSV array.

Perhaps you might want to try this?

If IsArray(payCsv(pay_id)) = False Then
    'create tempArray
    lc = 0
    Debug.Print "create array"
Else
    Debug.Print " array exists, we should be able to get ubound"
    lc = UBound(payCsv, 2) - LBound(payCsv, 2)
    l = l + 1
End If
Sign up to request clarification or add additional context in comments.

1 Comment

OMG...can't believe I missed that..i'll accept the answer when I can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.