Consulting

Results 1 to 4 of 4

Thread: Single Column Arrays or Vectors

  1. #1

    Single Column Arrays or Vectors

    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

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    832
    Location
    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

  3. #3
    Dave ... thank you sir!

  4. #4
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    832
    Location
    You are welcome. Thanks for posting your outcome. Dave

Posting Permissions

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