determine if array has at least one bound

Thread: determine if array has at least one bound

1. Senior Member
Join Date
Dec 1969
Posts
463

determine if array has at least one bound

If i declare a variable this way, dim arrVar(), it is considered an array. In fact isArray(arrVar) returns true. <BR>I need to create a conditional statement like the one below<BR><BR>If the array is in condition arrVar() Then<BR> execute code<BR>ElseIf array is in condition arrVar(bounds) Then<BR> execute code<BR>End If<BR><BR>Tough I don&#039;t know how to find if the array is still in the condition of when it has been dinamically declared the first time(arrVar()) or if it has bounds.

2. Senior Member
Join Date
Dec 1969
Posts
11,334

RE: determine if array has at least one bound

Don&#039;t dim it with the parens... then IsArray() should work.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
463

RE: determine if array has at least one bound

yeah well...that&#039;s not really a solution, cause If I need to ReDim the array I probably will have problems without declaring it as a dynamic array (with brackets)

4. Senior Member
Join Date
Dec 1969
Posts
11,334

Huh?

That&#039;s not true at all... this works<BR><BR>Dim theArray<BR>ReDim theArray(40)<BR>Response.Write UBound(theArray)<BR><BR>Ya get 40.<BR><BR>I guess you could also<BR><BR>If UBound(theArray) &#062; 0 Then<BR> &#039;it&#039;s got elements

5. Senior Member
Join Date
Dec 1969
Posts
463

depends

depends on the case you are working with. I am working with multidimensional arrays.<BR>And using redim with preserve. If using preserve you get an error if the array hasn&#039;t been declared with the brackets. That&#039;s natural because in that cae it is a normal variable.<BR><BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
96,118

A hack...

bounds = -1<BR>On Error Resume Next<BR>bounds = UBound( theArray, 2 )<BR>On Error GoTo 0<BR>If bound &#060; 0 Then<BR> Response "Array has not been dim&#039;ed yet"<BR>End If<BR>

7. Senior Member
Join Date
Dec 1969
Posts
463

RE: A hack...

yes, that will work fine. Tough, what does "GoTo 0" mean?

8. Senior Member
Join Date
Dec 1969
Posts
11,334

Turns off errors <nm>

boo

9. Senior Member
Join Date
Dec 1969
Posts
96,118

Actually, it turns them back *ON*

On Error Resume Next effectively turns *OFF* error checking by the VBS runtime. It just means "if you get an error, ignore it and contine on the [hl="yellow"]Next[/hl] line."<BR><BR>So On Error GoTo 0 really means "stop ignoring the errors" or "turn error checking back ON".<BR><BR>[GoTo 0 come from the old days when BASIC programs used line numbers. Zero was an illegal line number, so GOTO 0 effectively meant "do nothing". In various versions of BASIC, you could say <BR> On Error GoTo 173<BR>which meant "Go to line 173 when you get the error". So doing "GoTo 0" made a lot of sense, interpreted as "GoTo nowhere."]<BR><BR>

10. Senior Member
Join Date
Dec 1969
Posts
463

RE: Actually, it turns them back *ON*

I see it makes sense in fact. Jesus, Bill you know everything...<BR>Of most of the things I learn, I forget most of them in the next months....I really would like to what your trick is! <BR><BR>Anyway, thanks for the help<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
•