array in a loop (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


wizard_oz -> array in a loop (4/2/2005 7:10:24)

Hey, I have some variables from another page and I used the request to get it to an ARRAY, How do I make it in a look for eg:
this doesn't work:
dim arrSend(2)
for i=1 to 2
arrSend(i)=Request.QueryString("arrSend(i)")
next
for i=1 to 2
Response.Write arrSend(i)
next
but this is working:
dim arrSend(10)
arrSend(1)=Request.QueryString("arrSend(1)")
arrSend(2)=Request.QueryString("arrSend(2)")
Response.Write arrSend(1)
Response.Write arrSend(2)
WHY???????




yogaboy -> RE: array in a loop (4/2/2005 8:15:19)

Hi Wiz,

Arrays are numbered from 0, so ArrSend(2) has 3 spaces - 0, 1, 2. I don't understand why you start your FOR loops at 1, they should probably start at 0.

Also, you could bypass all this by using a SPLIT function. If you have 5 checkboxes with the same name...

myArrSend = Request.QueryString("arrSend")

myArray = SPLIT(myArrSend)

For i = 0 to Ubound(myArray)
Response.write myArray(i)
Next

Ubound is the upper bound or "top" of the array, which in this example will equal 4 because there are 5 items (0, 1, 2, 3, 4). SPLIT creates a zero-dimension array and puts the bit in the brackets into it, usually by delimiting by commas or spaces.

Hope that helps
Iain




yogaboy -> RE: array in a loop (4/2/2005 8:45:53)

Now I've read your other post I geddit a bit more.

Try this

For i = 1 To Request.QueryString("arrSend").Count
Response.Write Request.QueryString("arrSend")(i) & "<br />"
Next




wizard_oz -> RE: array in a loop (4/7/2005 2:48:00)

Thanks I will try it




rdouglass -> RE: array in a loop (4/7/2005 8:33:33)

quote:

myArray = SPLIT(myArrSend)


This line here will cause you some issues. You need to tell the SPLIT function where to slit at. You need something like:

myArray = SPLIT(myArrSend,",")

If you're requesting a list of multiple values like checkboxes or multi-select dropdowns, that code will split the string at each comma.

That any help?




wizard_oz -> RE: array in a loop (4/10/2005 2:08:45)

I think so, I will try it and let you know, Thanks again




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875