Array Is Null ?!?

Results 1 to 2 of 2

Thread: Array Is Null ?!?

  1. #1
    Alex Yong Guest

    Default Array Is Null ?!?

    Please help me with this : <BR><BR>Dim tempArray()<BR><BR>Then I have a processing of inserting value into the array when certain condition is met. Let say the condition is not met and nothing was inserted into tempArray. How do I detect whether there is anything in the array?<BR><BR>Eventhough nothing was inserted into the array, but the IsNull(tempArray) always give me False value. And the statement If tempArray = "" Then always give me the type mismatch error.<BR><BR>How do I detect if temparray is empty?

  2. #2
    Join Date
    Dec 1969

    Default Not an easy one! But solved...

    This is a good one!<BR><BR>The only way I found:<BR><BR>&#060;%<BR>Dim theArray( )<BR>...<BR>arrayNull = true<BR>On Error Resume Next<BR>arrayNull = ( LBound(theArray) &#060;&#062; 0 )<BR>On Error GoTo 0<BR><BR>If arrayNull Then ...<BR>%&#062;<BR><BR>How it works: Trying to do LBound on an array that has not yet been given any real dimensions causes an error.<BR><BR>Because we have asked to skip over the error, if one occurs then the value of the arrayNull variable is not altered, and so it stays false.<BR><BR>But if the array *does* have a dim assigned (e.g., by ReDim theArray(whatever) ), then there is no error. And since LBound of any valid array is *always* zero in VBS, the expression LBound(...) &#060;&#062; 0 will always evaluate to false, which is then assigned to the arrayNull variable. Presto.<BR><BR>Hokey, but it works!<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts