#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Dec 2011
    Posts
    17
    Rep Power
    0

    [Classic ASP] Dynamic Array Name Example


    I have been playing around with dynamic Array names and came up with the following working example. I hope it helps someone looking for a similar fix for their classic ASP project.

    Code:
    const loopcount = 10
    const catnum = 1
    
    for i = 0 to loopcount-1
    dim holder
    holder = i
    
    execute("redim preserve aryStr" & catnum & "(" & i+1 & ")")
    execute("aryStr" & catnum & "(" & i & ")=" & holder+1)
    
    response.write(eval("aryStr" & catnum & "(" & i & ")"))
    response.write(" - " & ubound(eval("aryStr" & catnum)) & "<br>")
    next
    I've found that the value must be assigned to a variable and can not be directly assigned in the execute statement. This is the reason for the "holder" variable.

    After running the code you can see that "i" and "ubound" are correctly outputted.

    I'm sure that there are other ways to accomplish this, but this is what I came up with and it is working for me.

    Cheers!
    Last edited by Blastyrant; December 19th, 2011 at 04:22 PM. Reason: Fixed title, made dynamic response.write statements

Similar Threads

  1. Dynamic two dimensional array & sorting
    By meishern in forum ASP Development
    Replies: 1
    Last Post: October 24th, 2006, 05:58 PM
  2. Dynamic Array Names...is it possible?
    By ubersnug in forum ASP Development
    Replies: 3
    Last Post: February 15th, 2005, 06:15 AM
  3. dynamic array
    By tiger99 in forum ASP Development
    Replies: 1
    Last Post: October 1st, 2004, 01:01 PM
  4. retrieve multi dim array value
    By aik_21 in forum ASP Development
    Replies: 4
    Last Post: July 15th, 2004, 08:27 AM
  5. Replies: 0
    Last Post: April 23rd, 2004, 09:49 AM

IMN logo majestic logo threadwatch logo seochat tools logo