1

Being new to ASP, I was trying to create a multi-dimensional array from a form. In php it was like :

<?php 
    $myArray = array();
    for($i = 0 $i< $myArray.size() $i++){ 
       
    myArray[$i] = array(field1=>"var1",field2=>var2);
    }
?> //syntax not exactly correct but you get the picture

I wanted to write this in ASP but I could not figure it out.

I needed to get values from my form in rows which I had done here, and then to put the values into the array.

    Function getResults(totalRows)

    dim results() 'my array for results
    for i = 0 to totalRows - 1 

    color = request.form("color"&i)
    width = request.form("width"&i)
    height = request.form("height"&i)


    results(i)("color") = color
    results(i)("height") = height
    results(i)("width") =  width

    response.write("color is " &results(i)("color")
    response.write("color is " &results(i)("height")
    response.write("color is " &results(i)("width")
    NEXT
End Function

I needed to return this array to work with it. I had tried looking online but it didn't seem to work out. Thanks in advance.

1 Answer 1

6

problem solved, I used incorrect syntax, and had to reDim the array - just in-case this helps somebody else

 dim results() 'my array for results
 ReDim Results(totalRows, 3)
 for i = 0 to totalRows - 1 
   results(i,0) = color
   results(i,1) = height
   results(1,2) =  width

   response.write("color is " &results(i,0)
   response.write("color is " &results(i,1)
   response.write("color is " &results(i,2)
NEXT

you could substitute the second index within another loop,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.