Create a (hard coded) matrix within VBA as array -


in vba can use array() create vector (1d array), eg. vector = array(1,2,3)

how can create 2x3 matrix? how 3x2? eg. matrix = array(1,2,3;4,6,7)

thanks

attempt

method 1 below solution albeit cumbersome. there nimble/larger arrays?

option explicit 1  private sub matrixdemo()   dim arr(2,3) variant   ' has 2 rows , 3 columns          arr(1,1) = 1             arr(1,2) = 2             arr(1,3) = 3                         arr(2,1) = 4              arr(2,2) = 5                arr(2,3) = 6            end sub 

method 2 more nimble have set commas define dimension. can run on fly?

dim matrix = new integer(2, 3) {{1, 2}, {3, 4}, {6, 7}} 

this function return matrix want.

just pass rows , columns need create_matrix(3, 2) , retrun array incremented values.

function create_matrix(x long, y long) variant      dim arr() variant ' matrix array     dim long ' rows     dim j long ' columns     dim k long ' increment counter       redim arr(1 y, 1 x)      = 1 y          j = 1 x              k = k + 1              arr(i, j) = k          next j ' next column       next ' next row       create_matrix = arr  end function 

your array should first declared variant


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -