user1899802
user1899802

Reputation: 135

ASP dynamic multi-dimensional array

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.

Upvotes: 1

Views: 15025

Answers (1)

user1899802
user1899802

Reputation: 135

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,

Upvotes: 6

Related Questions