Array question

1. Senior Member
Join Date
Dec 1969
Posts
2,892

## Array question

I have data stored in an array like:<BR><BR>arr(0) = 3125-1<BR>arr(1) = 6588-1<BR>arr(2) = 7544-2<BR><BR>...etc. I&#039;d like to cycle through this array and split each value at the "-" symbol, placing all into a new array like:<BR><BR>arrNew(0,0) = 3125<BR>arrNew(0,1) = 1<BR>arrNew(1,0) = 6588<BR>arrNew(1,1) = 1<BR>arrNew(2,0) = 7544<BR>arrNew(2,1) = 2<BR><BR>I have tried looping through 1st array with i=0 to UBound(arr) then Split(arr(1), "-"), but the split throws an error. Can anyone steer me in the right direction?<BR><BR>THanks<BR><BR>KurtW

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

## Should have worked

&#060;%<BR>arr = Array( "3125-1", "6588-2", "7544-3" )<BR>For ix = 0 To UBound(arr)<BR> arr(ix) = Split( arr(ix), "-" )<BR>Next<BR>%&#062;<BR><BR>That will return an array-of-arrays instead of the 2D array that you (thought you) wanted, but that&#039;s much more efficient for other reasons.<BR><BR>Instead of referencing<BR> arrNew(row,column)<BR>you&#039;ll now just use<BR> arr(row)(column)<BR><BR>[Besides, you had your rows and columns in arrNew backwards from standard VBS usage, anyway.]<BR><BR>

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

## RE: Should have worked

Not the way he did it<BR>arr(0) = 3125-1 <BR>arr(1) = 6588-1 <BR>arr(2) = 7544-2 <BR><BR>anything after the "-" gets dropped because he didnt define them as strings encased in qoutes "3125-1"<BR><BR>his way<BR>for i = 0 to 2<BR>Response.Write arr(1) & "&#060;/ br&#062;"<BR>Next<BR><BR>Im sure produced<BR>3125 <BR>6588 <BR>7544 <BR>which is why he got the error on the split...<BR><BR>Do what bidd showed you & it will work....<BR><BR>But still horrible.<BR>Why not forget this arrary to begin with and just build the array you want?<BR><BR><BR>

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

## Nope...try it yourself:

&#060;%<BR>Dim arr(2)<BR>arr(0) = 3125-1 <BR>arr(1) = 6588-1 <BR>arr(2) = 7544-2 <BR><BR>for i = 0 to 2<BR> Response.Write arr(i) & "&#060;br/&#062;"<BR> Response.Write Split( arr(i), "-" )(0) & "&#060;br/&#062;"<BR>Next<BR>Response.Write "Next line will give error:&#060;br/&#062;"<BR>Response.Write Split( arr(1), "-" )(1) & "&#060;br/&#062;"<BR>%&#062;<BR><BR>Yes, he may have goofed and forgotten the quotes. But it wouldn&#039;t have mattered, until/unless he finally tried to use<BR> Split( arr(i), "-" )( 1 )<BR>and then he would get a subscript error, which isn&#039;t what he said he got.<BR><BR>

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

## Ill give it a test but

in a bit<BR><BR>but i remember having this problem myself a while back where anything after the - was dropped<BR>If i recall, it was when you and I was talking about Atrax message board and padding the numbers 00000121-00000243 etc...<BR><BR>Ill check it out in a bit & let you know.<BR>

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

## HEY KURT!

Did you go look at the HTML forum?<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
2,892

## RE: Array question

Thanks Gents:<BR><BR>Lots to digest. Will read this all offline.<BR><BR>No Bill, I haven&#039;t been to HTMl forum for this, but I will take a look. Mostly I used my Wrox manual and read the FAQ&#039;s here.<BR><BR>KurtW

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

## Nope, It Errors....

Here is code<BR><BR>Dim arr(3)<BR>arr(0) = 3125-1 <BR>arr(1) = 6588-1 <BR>arr(2) = 7544-2<BR>arr(3) = "2930-1"<BR>For i = 0 to 3<BR>Response.Write arr(i) & "<BR>"<BR>Next<BR><BR>arrtest = Split(arr(2), "-")<BR>Response.Write arrtest & "&#060;/br&#062;"<BR><BR><BR>This is exactly whats written to page<BR><BR>3124<BR>6587<BR>7542<BR>2930-1<BR><BR>Microsoft VBScript runtime error &#039;800a0009&#039; <BR>Subscript out of range: &#039;[number: 1]&#039; <BR>/lgn_old/DelFor.asp, line 52 <BR><BR>arrtest = Split(arr(2), "-") &#039;&#060;&#060;&#060;Line 52<BR>If I use the 3rd with quotes<BR><BR>arrtest = Split(arr(3), "-") &#039;&#060;&#060;&#060;works like a charm<BR><BR>If I encase everything in quotes its all fine as well<BR><BR>Strange, but remembered that so specifically.<BR>Wonder why it drops everything after the "-" ?<BR><BR><BR><BR>

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

## Don't think I believe you...

Why would this line:<BR> arrtest = Split(arr(2), "-") <BR>give this message:<BR> Subscript out of range: &#039;[[hl="yellow"]number: 1[/hl]]&#039; <BR><BR>And of COURSE you need to encase everything in quotes, else you are just doing arithmetic with those minus signs. I thought you said that, yourself???<BR><BR><BR>

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

## I *KNOW* I don't believe you!!!

I tried it myself...and got a TYPE MISMATCH error on *THIS* line:<BR> Response.Write arrtest & "&#060;/br&#062;"<BR>because, of course, you are trying to write out AN ENTIRE ARRAY!<BR><BR>Change that to <BR> Response.Write arrtest(0) & "&#060;/br&#062;"<BR>and it works fine.<BR><BR>But add on ANOTHER line:<BR> Response.Write arrtest(1) & "&#060;/br&#062;"<BR>and *THEN* I get the <BR> Subscript out of range: &#039;[number: 1]&#039; <BR>that you showed.<BR><BR>Why do I suspect you didn&#039;t show us your *real* code???<BR><BR><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
•