
Array Comes Up Short . . .
This array should have three elements, but it only shows two. I get an error if try ary(2). Anyone see my mistake?<BR><BR>for x=1 to 10<BR><BR>set rs=server.createobject("ADODB.recordset")<BR>SQL=" SELECT * from attributevalues where prodid='001' and vcode='9135'"<BR>rs.open sql, conn, 3<BR><BR>response.write "<BR>"<BR><BR>if not rs.eof then<BR><BR>response.write rs("a"&x)<BR><BR>ar= ar & rs("a"&x) & "?#$"<BR>ary=split(ar, "?#$")<BR>response.write ary(0)<BR>response.write ary(1)<BR>'response.write ary(2)<BR> <BR><BR>end if<BR><BR>)<BR>next <BR>

RE: Array Comes Up Short . . .
What is the value of the "ar" variable? If you do Response.Write UBound(ary), what does it give you?<BR><BR>Doug

RE: Array Comes Up Short . . .
I only get these numbers, I suppose showing the loop cycle<BR><BR><BR>1<BR>2<BR>3<BR>4<BR>5<BR>6<BR>7<B R>8<BR>9<BR>10

RE: Array Comes Up Short . . .
What gave these numbers? Which response.write?

response.write Ubound(ary)
response.write Ubound(ary)

Figured it Out 
Make ar inside the IF<BR><BR>Make arr=arr + ar + "?#$" outside the IF inside the next<BR><BR>arry=split(arr, "?#$") outside the next

RE: response.write Ubound(ary)
You are getting the encrementing value because you are not clearing the AR value after each loop iteration so you keep appending the array separator to the string. Each time you get a higher upperbound.<BR><BR>I guess my next question is, what is the value of "response.write rs("a"&x)"?<BR><BR>Doug

That code is pure nonsense!
TEN TIMES you will create a recordset.<BR><BR>EACH TIME you will have the SAME records in the recordset.<BR><BR>TEN TIMES you will get the FIRST record in the recordset.<BR><BR>WHY?????????????<BR><BR>Anyway, the bug is that you are doing the SPLIT *BEFORE THE ENTIRE STRING IS BUILT*. <BR><BR>You are doing the SPLIT after adding just ONE value to the string. So OF COURSE it only has 2 elements!<BR><BR>When x=1, then the array will have 2 elements.<BR>When x=2, then the array will have 3 elements.<BR>When x=3, then the array will have 4 elements.<BR>...<BR>When x=10, then the array will have 11 elements.<BR><BR>What did you EXPECT??<BR><BR>Throw away that code and start over!<BR><BR><%<BR>...<BR>SQL="SELECT * from attributevalues where prodid='001' and vcode='9135'"<BR>Set RS = conn.Execute(SQL)<BR><BR>IF RS.EOF Then<BR> Response.Write "DISASTER! No record matching request!"<BR> Response.End<BR>End If<BR><BR>Dim ary(10)<BR>For x = 1 To 10<BR> ary(x) = RS("a"&x)<BR>Next<BR>...<BR>%><BR><BR>I can't figure out why you wanted to build the silly string in the first place, instead of just creating the array that you wanted directly.<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

Forum Rules

