PDA

View Full Version : [SOLVED] Array problems ... need help



dennygibson
02-28-2019, 10:01 AM
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#

dennygibson
02-28-2019, 10:01 AM
Btw ... the full code is well over 500 lines ... which is why I'm not posting it now ...

Paul_Hossler
02-28-2019, 10:09 AM
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

dennygibson
02-28-2019, 10:20 AM
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?

dennygibson
02-28-2019, 10:28 AM
The error box flags F

dennygibson
02-28-2019, 10:39 AM
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

Paul_Hossler
02-28-2019, 05:17 PM
since MMULT and MINVERSE are worksheet functions, F should be Dim-ed as plain Variant and not an array

dennygibson
03-01-2019, 08:36 AM
Paul … thanks! I ended up just making the vectors 2x1 matrices and the function worked.