PDA

View Full Version : Single Column Arrays or Vectors



dennygibson
02-18-2019, 01:56 PM
My journey from Fortran to VBA has been interesting … here's something I ran into today:

'I have two arrays (D and F) in my code that should be vectors:

Dim D(1 to 2) As Double
Dim F(1 to 2) As Double
Dim C(1 To 2, 1 To 2)

when I try to execute the following:
C(1, 1) = 1#
C(1, 2) = 0#
C(2, 1) = 0#
C(2, 2) = 1#
D(1) = x1 + 3 * x2
D(2) = 2 * x1 + 2 * x2

F = WorksheetFunction.MMult(C, D)

I get "Can't assign to array" from the compiler … when I had the D and F as Dim F(1 To 2, 1 To 1) and
Dim D(1 To 2, 1 To 1) it all worked … can someone explain why?


Thanks!
Denny

Dave
02-18-2019, 05:37 PM
Denny U have to Dim arrays as variants not as double. If you don't declare a storage type then variables are dimmed as Variant so your initial declaration would have worked. HTH. Dave

dennygibson
02-18-2019, 05:59 PM
Dave ... thank you sir!

Dave
02-19-2019, 08:51 PM
You are welcome. Thanks for posting your outcome. Dave