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

Discussion in 'ASP General' started by curtis m. west, Apr 28, 2004.

  1. 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
    curtis m. west, Apr 28, 2004
    #1
    1. Advertising

  2. 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

    curtis m. west wrote:
    > 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


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Apr 28, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. teo
    Replies:
    3
    Views:
    513
  2. Bobby Chamness
    Replies:
    2
    Views:
    2,376
    Joe Smith
    Apr 22, 2007
  3. Jamie Herre
    Replies:
    1
    Views:
    175
    why the lucky stiff
    Jan 7, 2005
  4. Java  script  Dude

    IE name="name" & form.name property bug

    Java script Dude, Jun 29, 2004, in forum: Javascript
    Replies:
    5
    Views:
    223
    Java script Dude
    Jun 30, 2004
  5. Dave Angel
    Replies:
    0
    Views:
    173
    Dave Angel
    Aug 30, 2012
Loading...

Share This Page