DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic array - isempty or isnull?

Solved!
Go to solution

Hi,

 

I can't get a piece of code to work that tries to determine whether a dynamic array has been used or not.

 

A dynamic array is defined at the head of the code: VarArray(). If any of the batch of files being processed don't meet certain criteria then VarArray is redimensioned and the suspect file name added to it. However, if all the files are valid then VarArray is never redimensioned.

 

Later in the code I wish to extract the contents of VarArray for a message box so I need to interrogate it to see if it has any contents. I have tried all the following and get either an error message or the line is ignored and the IF code entered:

If IsNull(VarArray) = False Then
If IsNull(VarArray()) = False Then
If IsNull(VarArray(0)) = False Then
If IsEmpty(VarArray) = False Then
If IsEmpty(VarArray()) = False Then
If IsEmpty(VarArray(0)) = False Then

I have also tried If Not etc... in case that made any difference. It didn't.

 

If I watch the Current Variable Contents window then VarArray always shows {...} when unused. How do I correctly define the code to determine whether VarArray was ever redimensioned?

 

Regards.

0 Kudos
Message 1 of 5
(1,565 Views)

By way of an update, and using the example from the IsEmpty help page:

 

Dim MyVar, MyVar2()
Call MsgBox(IsEmpty(MyVar)) 'Returns True
Call MsgBox(IsEmpty(MyVar2)) 'Returns False

 

It seems IsEmpty behaves differently with dynamic arrays. Why is this and what can I do to circumvent this behaviour?

 

Regards.

0 Kudos
Message 2 of 5
(1,554 Views)
Solution
Accepted by topic author Simon_Aldworth

Hi Simon_Aldworth,

 

You can initialize the dynamic array with 0, then you can askas follows:

dim VarArray()
redim VarArray(0)

if isarray(VarArray) then
  if uBound(VarArray) = 0 then msgbox "No change"

  redim VarArray(1)
  if uBound(VarArray) > 0 then msgbox "Array size is: " & uBound(VarArray)
end if

 

Greetings

Walter

0 Kudos
Message 3 of 5
(1,517 Views)

Thanks Walter.

 

It would be great if the IsEmpty behaviour was consistent for different variable types, or at least a note in the helps files saying it behaves differently with dynamic arrays.

 

Regards.

0 Kudos
Message 4 of 5
(1,505 Views)

Hi Simon_Aldworth,

 

Yes, I agree, but this must be discussed with Microsoft because IsEmpty is a VBS function and no DIAdem function.

 

Greetings

Walter

0 Kudos
Message 5 of 5
(1,501 Views)