Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: ASP Arrays

  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    ASP Arrays

    In PHP and JavaScript you can sort of NAME array values, I don't know how to say it.

    PHP Code:
    $data['firstname'] = "Martyn";
    $data['lastname'] = "Ball";

    echo 
    $data['firstname']." ".$data['lastname']; 
    The above works in PHP. but when I try this in ASP it does not work...
    PHP Code:
    Create array
    Dim data()
    data("fname") = request.querystring("fname")
    data("sname") = request.querystring("sname")
    data("email") = request.querystring("email")
    data("password") = md5(request.querystring("password"))
    data("passwordc") = md5(request.querystring("passwordc")) 
    I saw online that you must use "(" ")" instead of "[" "]" but that still doesn't work...

    I get the following error:
    Code:
    Microsoft VBScript runtime error '800a0009'
    
    Subscript out of range
    
    /nightclub_photography/asp/register.asp, line 7
    This starts on line 7:
    Code:
    data("fname") = request.querystring("fname")

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,947
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Nope, can't do that with ASP arrays. But there's an easy substitute:
    Code:
    Set data = Server.CreateObject("Scripting.Dictionary")
    data.Add "fname", request.querystring("fname") 
    data.Add "sname", request.querystring("sname") 
    data.Add "email", request.querystring("email") 
    data.Add "password", md5(request.querystring("password")) 
    data.Add "passwordc", md5(request.querystring("passwordc"))
    ... 
    If data.Exists("fname") Then
        Response.Write "First name is " & data("fname")
    End IF
    ... and so one ...
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (05-17-2013)

  • #3
    Regular Coder
    Join Date
    May 2012
    Location
    USA
    Posts
    102
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Asp and Asp.Net, both are different programming platforms, so there is no chance that an Asp code will work in Asp.Net.

  • #4
    Regular Coder
    Join Date
    May 2012
    Location
    USA
    Posts
    102
    Thanks
    0
    Thanked 7 Times in 7 Posts
    I tried the code that Old Pedant has shared for multiple arrays, but unfortunately it didn't worked.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,947
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Quote Originally Posted by annaharris View Post
    I tried the code that Old Pedant has shared for multiple arrays, but unfortunately it didn't worked.
    Thus proving, once again, that "Anna Harris" should keep "her" nose out of ASP coding since clearly "she" knows nothing whatsoever about it.

    Here is a a complete working page:
    Code:
    <html>
    <body>
    <%
    Set data = Server.CreateObject("Scripting.Dictionary")
    data.Add "fname", request.querystring("fname") 
    data.Add "sname", request.querystring("sname") 
    data.Add "email", request.querystring("email") 
    
    If data.Exists("fname") Then
        Response.Write "First name is " & data("fname") & "<hr/>" & vbNewLine
    End IF
    
    For Each key In data.Keys
        Response.Write "Key " & key & " has value " & data(key) & "<br/>" & vbNewLine
    Next
    %>
    </body>
    </html>
    Save that code as some ASP page on your server. Let's say you save it as demo.asp.

    And then hit that same page from your browser, something like this:
    Code:
    http://localhost/demo.asp?fname=zamboni&sname=wiggles&email=silly@goof.com
    And you will see this for the page output:
    Code:
    First name is zamboni
    Key fname has value zamboni
    Key sname has value wiggles
    Key email has value silly@goof.com
    Maybe "anna harris" (which is clearly an entirely FAKE NAME) should stick to PHP? Or underwater basketweaving?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-11-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •