[thelist] ASP Loop Question
Steve Cook
steve.cook at evitbe.com
Wed Mar 20 10:34:01 CST 2002
Ah! That one I can answer ;-)
The first example is a pointer to a value. A collection (like the request
collection for instance) is kind of like a two part array. Each key, value
pair consists of two values (in effect). Whereas an array is built using
numbers:
arr[1] = "value 1"
arr[2] = "value 2"
arr[3] = "value 3"
arr[4] = "value 4"
a collection you can think of as being built using strings
arr("value1") = "value 1"
arr("value2") = "value 2"
arr("value3") = "value 3"
arr("value4") = "value 4"
(It's not actually defined that way, but it serves as a loose visual
representation of the data)
Like any other string in VBScript, you can build it up using concatenation:
count = 1
arr("value" & 1) = "value 1"
On the other hand in the second example you give, what is happening is that
you are simply assigning a string value to a variable.
x = 1
variable = "variable_" & x
Response.Write variable
will print "variable_1"
all you have done is assigned the string value to the variable with the name
"variable".
See?
By the way, if you are interested in building your own collections in
VBScript, you should look at the Dictionary Object in whichever ASP
reference you use. They are a very useful way of storing data. Having come
into programming via perl, I think of them as "hashes" which are used very
frequently in perl.
Have fun!
.steve
----------------------------------
WapWarp - http://wapwarp.com
Wap-Dev - http://www.wap-dev.net
Cookstour - http://cookstour.org
----------------------------------
> <%
> for x = 1 to 2
> variable = request.form("variable_" & x )
> next
> %>
>
> works, whereas
>
> <%
> for x = 1 to 2
> variable = "variable_" & x
> next
> %>
>
> does not.
>
> I wonder why.
>
> Josh
More information about the thelist
mailing list