Results 1 to 5 of 5

Thread: Passing arrays - can it be done??

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    343
    Hello,

    How can I pass an array from one page to the next.

    Eg.

    In page 1 I have
    <%
    dim array1(100)

    array1(1) = "hello"
    array1(2) = "word"
    %>

    I now submit/post this form to page2 where I want to do something like


    <%
    dim array2(100)
    array2 = request.form array1

    response.write array2(1)
    response.write array2(2)
    %>

    Which must results in - "helloworld".

    Can it be done.

    Thanks,
    T

  2. #2
    Junior Member
    Join Date
    Apr 2001
    Location
    Manassas, Va.
    Posts
    18
    You will need to pass the values to the next page us a FORM or by putting the values in the QueryString. Just assign the values in your form to have the same name.

    Example:
    Code:
    <form action="page2.asp" method="get">
    
    <% 
    dim array1(100) 
    
    array1(1) = "hello" 
    array1(2) = "word" 
    
    For i = LBound(array1) to UBound(array1)
    %>
    
    <input type="hidden" name="array1" value="<%=array(i)%>">
    
    <%
    Next
    %>
    
    </form>
    page2.asp should have the following code
    Code:
    <% 
    dim array1(100) 
    
    For i = 1 to Request.QueryString("array1").Count
       array(i - 1) = Request.QueryString("array1")(i)
    Next
    %>
    This should take care of it, for an array of pre determined size. If the array is dynamic you will need to ReDim it accordingly.

    Also remember that VBScript arrays are zero based by default.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    343

    Talking

    Thanks kkolstad,

    It works great!!

    T

  4. #4
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    Another option will be push store the array in a session or application wide variable.
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  5. #5
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    yep works real well I did this

    Code:
    <%for p = 0 to ubound(strSt)%>
    			<input type="hidden" name="ArrayState" value="<%=strSt(p)%>">
             <%next%>
             
             <%for d = 0 to ubound(strSt)%>
    			<input type="hidden" name="ArrayTotal" value="<%=strTl(d)%>">
             <%next%>

Posting Permissions

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



Click Here to Expand Forum to Full Width