Why won't arr(0) print when lbound(arr) retur

# Thread: Why won't arr(0) print when lbound(arr) retur

1. Senior Member
Join Date
Dec 1969
Posts
290

## Why won't arr(0) print when lbound(arr) retur

Hi there,<BR><BR>I have this code:<BR><BR>value_key_arr = Split(sort_arr(1),"&#124&#124")<BR>If (IsArray(value_key_arr)) Then<BR> response.write("hello")<BR> response.write(lbound(value_key_arr))<BR>End If<BR><BR>which prints "hello0"<BR><BR>But if I change it to:<BR><BR>value_key_arr = Split(sort_arr(1),"&#124&#124")<BR>If (IsArray(value_key_arr)) Then<BR> response.write("hello")<BR> response.write(value_key_arr(0))<BR>End If<BR><BR>It gives me a "Subscript out of range: &#039;[number: 0]&#039;" on that line.<BR><BR>What the heck?!<BR><BR>Can anyone explain this to me?

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

## Debug...

&nbsp;<BR>Response.Write "sort_arr(1) is: " & sort_arr(1) & "&#060;HR&#062;"<BR>value_key_arr = Split(sort_arr(1),"&#124&#124")<BR>If (IsArray(value_key_arr)) Then<BR> Response.Write "lbound(value_key_arr) is " & LBound(value_key_arr) & "&#060;P&#062;"<BR> response.write "element zero is: " & value_key_arr(0) & "&#060;P&#062;"<BR>End If<BR><BR>Yeah, something weird is going on, but we need to see debug in situ.<BR><BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
290

## RE: Debug...

Here&#039;s what I got from the debug:<BR><BR>sort_arr(1) is+1&#124&#124 2004-05-14+<BR>-----------------------------<BR>hello0 <BR><BR>using the code:<BR><BR>value_key_arr = Split(sort_arr(1),"&#124&#124")<BR>Response.Write "sort_arr(1) is+" & sort_arr(1) & "+&#060;HR&#062;" <BR>If (IsArray(value_key_arr)) Then<BR> response.write("hello")<BR> response.write(lbound(value_key_arr))<BR>End If<BR><BR>but what&#039;s strange now is sometimes it came up:<BR><BR>sort_arr(1) is++<BR><BR>so I have to figure out why that is.<BR><BR>Thanks for your help!

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

## Yeah, but then...

...the ISARRAY should show up as not an array. No?<BR><BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
6,476

## Not if

it contains a null or maybe its an empty value...<BR>it will show up as an array...<BR>even tho it really is nothing....<BR><BR>Just a bug in the Split() Assignment to the variable...<BR>

6. Senior Member
Join Date
Dec 1969
Posts
6,476

## And isEmpty or isNull will not work

to check the value...<BR><BR>Only thing is to be sure and check the values "Before adding it to the arrays"...<BR>If nothing or null exists, dont add to that new array element...<BR>

7. Senior Member
Join Date
Dec 1969
Posts
6,476

I can think of would be to deal with it before building the 2nd array...<BR><BR>Maybe give something like this a test run and see what it produces for the output....<BR><BR>&#060;%<BR>IF "" & sort_arr(1) = "" Then<BR> &#039;No value so skip everything<BR> Response.Write "This elememnt contains no value &#060;/br&#062;"<BR>ELSE<BR> &#039;We have a value continue<BR> value_key_arr = Split(sort_arr(1),"&#124&#124")<BR> IF isArray(value_key_arr) Then<BR> response.write("hello") <BR> response.write(value_key_arr(0))End IF<BR> Else<BR> Response.Write "Is still not an array&#060;/br&#062;"<BR> End IF <BR>End IF<BR>%&#062;<BR><BR>Dealing with it befor hand is only way around that.<BR> <BR>

8. Senior Member
Join Date
Dec 1969
Posts
6,476

## Sorry a bug in there

Just noticed an "extra" (end if) was stuck on the end of this line in previous version...<BR>response.write(value_key_arr(0))End IF <BR><BR>Below is corrected so use it instead...<BR><BR><BR>&#060;% <BR>IF "" & sort_arr(1) = "" Then <BR> &#039;No value so skip everything <BR> Response.Write "This elememnt contains no value &#060;/br&#062;" <BR>ELSE <BR> &#039;We have a value continue <BR> value_key_arr = Split(sort_arr(1),"&#124&#124") <BR> IF isArray(value_key_arr) Then <BR> response.write("hello") <BR> response.write(value_key_arr(0))<BR> Else <BR> Response.Write "Is still not an array&#060;/br&#062;" <BR> End IF <BR>End IF <BR>%&#062; <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
•