Array Declaration Problem ??
Lately I have been using a lot of GLOBAL declarations to avoid some
complications in passing my variables...
I typically would declare my variable (or array) like this at the top of the
module I need to use it in:
Public myArray(1 To 1000, 1 To 1000) As String
Also I have been declaring my arrays to an upper bound number that should
accommodate any scenario (ie - 10,000 or 100,000 depending on the
situation). You should also be able to use a ReDim elsewhere in your code,
but I do not used that feature myself.
Then I can reference it anywhere in my module (a sub routine or a function)
and never have to pass a variable.
I know this is not the most efficient method, but it works out pretty good
for me...
Just a thought...
NOTE: I do not use this method for all my variable (arrays)... Just the ones
I need to reference in other sub-routines or functions.
Mark Ivey
"monir" wrote in message
...
(This is a cross-post)
Hello;
I'm trying to correctly pass the range B11:C14 to the Function MyRoots()
and
return the results by the array function to cells I11:J13.
Notice the use of ReDim. Declaring Dim a(m+1,2) As Double in Function
MyRoots() would produce a compile error: "Constant expresion required",
and
also I couldn't declare "a" as a 2D dynamic array!
I suspect the array variables declaration in the following example is the
problem.
The array Function MyRoots() incorrectly returns 0.0 results to cells
I11:J13.
cell B8::3
cell B9: myTrue
cells B11:C14 numerical values
cells I11:J13:: array function {=MyRoots(B11:C14, B8, B9)}
Function MyRoots (a, m As Integer, polish As String)
ReDim a(m + 1, 2) As Double
ReDim roots(m, 2) As Double
Dim j As Integer, its As Integer
Dim x(2) As Double
ReDim ad(m + 1, 2) As Double
......................................my code............
For j = 1 To m + 1
ad(j, 1) = a(j, 1)
ad(j, 2) = a(j, 2)
Next j
......................................my code............
Call Laguer (ad, j, x, its)
......................................my code............
roots(j, 1) = x(1)
roots(j, 2) = x(2)
......................................my code............
MyRoots = roots
End Function
Sub Laguer (a, m, x, its)
Dim x1(2) As Double
......................................my code............
x(1) = x1(1)
x(2) = x1(2)
......................................my code............
Exit Sub
End Sub
Your expert help would be greatly appreciated.
Regards.
|