variable an object? if yes, is there a name property?

C

curtis m. west

hello NG

i would like to fill all the "requested fields" of a form into variables.
i do this by hand now:

strUsername = request.form("strName")
strPassword = request.form("strPassword")
..
..

is it possible to do this using a loop?
i have no problem getting the values:

for i = 1 to Request.Form.Count

<myvalue> = Request.Form.Item(i)
next

but how can i fill these values into variables with the corespondig name?
something like:
variable.add
variable.name = Request.Form.Key(i)
variable.value = Request.Form.Item(i)

got the idea?!

tnx for any help!
greetz, q
 
B

Bob Barrows [MVP]

Why do the variables need to be named? The program does not care what the
variables are called. Ony you, the programmer, care what they are named. You
are wasting your time and potentially adding overhead to your application
for very little reason.

Sure, you can use Execute to dynamically declare a variable,

for each key in request.form
Execute "Dim str" & key
Execute "str" & key & " = " request.form(key)
next

but then you would need to use Execute every time you need to get the values
from these variables, if that is possible ...

You can simply use a multidimensional array and assign the values to array
elements.

dim arForm,i
i=0
redim arForm(1,request.form.count - 1)
for each key in request.form
ar(0,i) = key
ar(1,i) = request.form(key)
next

For a slightly less efficient solution, but easier to use, you can use a
Dictionary object:

dim d,key
set d=server.createobject("Scriptinig.Dictionary")
for each key in request.form
d.add key,request.form(key)
next

For more information go to msdn.microsoft.com/library and look up the
documentation for the Dictionary object.

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top