Consulting

Results 1 to 8 of 8

Thread: Array problems ... need help

  1. #1

    Array problems ... need help

    The following bit of code is causing a problem ... as you can see a_b is a 2x2 matrix but b_b and c_b are vectors. I'm getting a compile error saying that b_b is a type mismatch.
    This is an area that drives me crazy ... can anyone explain what's going on? This sort of thing costs me way more time to get straight than any coding difficulties I've ever encountered!


    Dim a_b(1 To 2, 1 To 2) As Variant
    Dim b_b As Variant
    Dim c_b As Variant


    a_b(1, 1) = 1# / 4#
    a_b(1, 2) = 1# / 4# - Sqr(3#) / 6#
    a_b(2, 1) = 1# / 4# + Sqr(3#) / 6#
    a_b(2, 2) = 1# / 4#
    b_b(1) = 1# / 2#
    b_b(2) = 1# / 2#
    c_b(1) = 1# / 2# - Sqr(3#) / 6#
    c_b(2) = 1# / 2# + Sqr(3#) / 6#

  2. #2
    Btw ... the full code is well over 500 lines ... which is why I'm not posting it now ...

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    1. I'm guessing you really intended this. I'd make them Double since it's more efficient than Variant


    Dim a_b(1 To 2, 1 To 2) As Double Dim b_b (1 To 2) As Double Dim c_b (1 To 2) As Double
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    Paul ... this is driving me nuts ... so I tried this

    Dim a_b(1 To 2, 1 To 2) As Variant
    Dim b_b(1 To 2) As Double
    Dim c_b(1 To 2) As Double
    Dim D(1 To 2) As Double
    Dim F(1 To 2) As Double

    D(1) = B1 / A1
    D(2) = C2 * W1
    F = WorksheetFunction.MMult(WorksheetFunction.MInverse(Coef), D) 'and got "can't assign an array"

    Thoughts?


  5. #5
    The error box flags F

  6. #6
    Dim Coef(1 To 2, 1 To 2) As Double
    Dim a_b(1 To 2, 1 To 2) As Double
    Dim b_b(1 To 2) As Double
    Dim c_b(1 To 2) As Double
    Dim D(1 To 2) As Double
    Dim F(1 To 2) As Double
    
    
    D(1) = B1 / A1 D(2) = C2 * W1 F = WorksheetFunction.MMult(WorksheetFunction.MInverse(Coef), D) 'and got "can't assign to an array" with F highlighted
    Last edited by dennygibson; 02-28-2019 at 11:58 AM.

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    since MMULT and MINVERSE are worksheet functions, F should be Dim-ed as plain Variant and not an array
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    Paul … thanks! I ended up just making the vectors 2x1 matrices and the function worked.

Posting Permissions

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