Array Problem

gar3th_jon3s
09-09-2003, 09:13 AM
Hi, I am having the following problem:

How can I check if an array has been dim'ed as dynamic, has been redim'ed and populated?

The only way around this I have found is to do the following:



Dim vNumbers as variant
vNumbers = SomeFunction() ' this returns as array of doubles

If IsArray(vNumbers) Then
' Do stuff..
End If



I dont want to use variants though, ideally i would like to do something like:



Dim aNumbers() as Double
aNumbers = SomeFunction()

' Need to check if array has anything in now.. HOW!?



I always get errors because obviously the array needs to be redim'ed before it can be used.

Dont know if i have explained that very well, cheers for any help
Gareth JOnes

Thinker
09-09-2003, 09:21 AM
Look at this very, very recent thread...
http://www.visualbasicforum.com/showthread.php?threadid=105700

Baradin
09-09-2003, 09:23 AM
Dim aNumbers() as Double
aNumbers = SomeFunction()

' Need to check if array has anything in now.. HOW!?





Well you are going to get an error whilst checking an array that's empty so I use an errortrap and then in the errortrap msgbox that the array is empty. ie:


Onerror goto errtrap

Ubound(Arrayname)

errtrap
Msgbox "No elements in array" , vbokonly

Thinker
09-09-2003, 09:36 AM
No, don't do that when the solution in the other thread is so very much better.

Baradin
09-09-2003, 09:39 AM
No, don't do that when the solution in the other thread is so very much better.


I posted then I saw yer post and yup yup that it eversomuch more elegant and clean. Do that!!

gar3th_jon3s
09-09-2003, 09:48 AM
i have been looking for a way to do that for ages, that is the best tip ive had in a long time, thanks very much :D

gar3th_jon3s
09-10-2003, 02:06 AM
i have been looking for a way to do that for ages, that is the best tip ive had in a long time, thanks very much :D

Hi, I have just implemented your tip in my code, and I get an "Expression is too complex" error?! Im not doing anything too complex i dont think, but i do sever of these checks one after another.. have you ever come accross this? I've had to change it back to my original way of using variants and this works fine? seems strange..

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum