Objects and collections

Discussion in 'ASP General' started by Roland Hall, May 17, 2005.

  1. Roland Hall

    Roland Hall Guest

    I have two questions which I am unable to find answers to:

    1. What is the difference between Request.Form and Request.Item?

    I can do this:

    dim obj, postback, o
    postback = Request.Form("postback")
    if postback <> "" then
    for each obj in Request.Form
    o = Request.Item(obj)
    if o <> "postback" then
    session(obj) = o
    end if
    Response.Write session(obj) & "<br />" & vbCrLf
    next
    end if

    What makes Request.Item different in this respect than Request.Form? Is
    there a benefit one way or the other?

    2. Is it possible to use FOR...EACH, with a form and make the variable an
    object?

    Ex.

    If I use:
    for each obj in Request.Form

    obj is not an object as I cannot then write:

    Response.Write obj.value to get the value of the form variable.

    If my form was:

    <input type="text" name="iname" value="" />

    and I typed in Roland and submitted, I cannot with the FOR...EACH use
    obj.value to get the value. Is there a way to do it that I am not aware of?

    TIA...

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 17, 2005
    #1
    1. Advertising

  2. Roland Hall wrote:
    > I have two questions which I am unable to find answers to:
    >
    > 1. What is the difference between Request.Form and Request.Item?


    Request.Item(something) is the same as Request(something). Basically, Item
    is the default property, and you've requested the first itme in all the
    Request object's collections whose key matches your specification

    > What makes Request.Item different in this respect than Request.Form?
    > Is there a benefit one way or the other?


    I'm sure you've read all our admonitions in the past about failing to
    specify the collection whose item you wish to retrieve...

    >
    > 2. Is it possible to use FOR...EACH, with a form and make the
    > variable an object?


    for each key in Request.Form
    Response.Write key & ": " & Response.Form(key)
    next

    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], May 17, 2005
    #2
    1. Advertising

  3. Roland Hall

    Roland Hall Guest

    "Bob Barrows [MVP]" wrote in message
    news:...
    : Roland Hall wrote:
    : > I have two questions which I am unable to find answers to:
    : >
    : > 1. What is the difference between Request.Form and Request.Item?
    :
    : Request.Item(something) is the same as Request(something). Basically, Item
    : is the default property, and you've requested the first itme in all the
    : Request object's collections whose key matches your specification
    :
    : > What makes Request.Item different in this respect than Request.Form?
    : > Is there a benefit one way or the other?
    :
    : I'm sure you've read all our admonitions in the past about failing to
    : specify the collection whose item you wish to retrieve...
    :
    : >
    : > 2. Is it possible to use FOR...EACH, with a form and make the
    : > variable an object?
    :
    : for each key in Request.Form
    : Response.Write key & ": " & Response.Form(key)
    : next

    key is the form element
    Response.Form(key) would return the value but how can I make key an object
    and use key.value to get the value?

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 17, 2005
    #3
  4. Roland Hall wrote:

    >>> 2. Is it possible to use FOR...EACH, with a form and make the
    >>> variable an object?

    >>
    >> for each key in Request.Form
    >> Response.Write key & ": " & Response.Form(key)
    >> next

    >
    > key is the form element


    Actually, it is the key of the form element

    > Response.Form(key) would return the value but how can I make key an
    > object and use key.value to get the value?
    >


    Unfortunately, the vbscript enumerator does not work that way with these
    collections. The enumerator exposes the item keys, not the items themselves.
    It took me a while to figure this out, so I feel your pain.

    Bob Barrows
    --
    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], May 17, 2005
    #4
  5. Roland Hall

    Roland Hall Guest

    "Bob Barrows [MVP]" wrote in message
    news:%...
    : Roland Hall wrote:
    :
    : >>> 2. Is it possible to use FOR...EACH, with a form and make the
    : >>> variable an object?
    : >>
    : >> for each key in Request.Form
    : >> Response.Write key & ": " & Response.Form(key)
    : >> next
    : >
    : > key is the form element
    :
    : Actually, it is the key of the form element

    Ah, ok.

    : > Response.Form(key) would return the value but how can I make key an
    : > object and use key.value to get the value?
    : >
    :
    : Unfortunately, the vbscript enumerator does not work that way with these
    : collections. The enumerator exposes the item keys, not the items
    themselves.
    : It took me a while to figure this out, so I feel your pain.

    That's unfortunate. Well good for me that I have you to provide that answer
    so my insanity will not come from trying to figure this one out. Thanks
    Bob.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 17, 2005
    #5
    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. Rob Thomas
    Replies:
    3
    Views:
    375
  2. Doug Poland
    Replies:
    9
    Views:
    735
    VisionSet
    Sep 27, 2003
  3. Timo Nentwig

    stale objects in collections

    Timo Nentwig, Aug 21, 2006, in forum: Java
    Replies:
    9
    Views:
    499
    Patricia Shanahan
    Aug 22, 2006
  4. walterbyrd
    Replies:
    35
    Views:
    768
    Bruno Desthuilliers
    Jun 29, 2007
  5. mutex
    Replies:
    0
    Views:
    216
    mutex
    Jul 27, 2003
Loading...

Share This Page