Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
(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. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Mark;
Thank you for your thoughts. I think the declaration statement ReDim a(m+1,2) in my sample code Function MyRoots() should be removed altogether, since the array is passing to the function as an array argument ! Now I'm getting #VALUE! results instead of 0. Using global declarations and sizing arrays to the max expected are possible workarounds, but don't you agree that having the array declarations automatically adjusted to the situation "looks" more efficient ?? Regards. "Mark Ivey" wrote: 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. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am not clear what your code is doing, especially the ,,, my code ... bits,
but your array declaration is definitely wrong. Try this Function MyRoots(a, m As Integer, polish As String) Dim a As Variant, Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) For j = 1 To m + 1 ad(j, 1) = a(j, 1) ad(j, 2) = a(j, 2) Next j Call Laguer(ad, j, x, its) Roots(j, 1) = x(1) Roots(j, 2) = x(2) MyRoots = Roots End Function -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "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. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Bob;
Thank you kindly for your prompt reply. I've tried your suggestion. Function MyRoots(a, m As Integer, polish As String) Dim a As Variant, Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) ..............................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) MyRoots = Roots End Function It produces the compile error: "Duplicate declaration in current scope" with reference to the "a" declaration in: Dim a As Variant, Roots As Variant Any suggestion ?? Regards. "Bob Phillips" wrote: I am not clear what your code is doing, especially the ,,, my code ... bits, but your array declaration is definitely wrong. Try this Function MyRoots(a, m As Integer, polish As String) Dim a As Variant, Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) For j = 1 To m + 1 ad(j, 1) = a(j, 1) ad(j, 2) = a(j, 2) Next j Call Laguer(ad, j, x, its) Roots(j, 1) = x(1) Roots(j, 2) = x(2) MyRoots = Roots End Function -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "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. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry, missed the parameter
Function MyRoots(a As Variant, m As Integer, polish As String) Dim Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) ' ..............................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) MyRoots = Roots End Function -- __________________________________ HTH Bob "monir" wrote in message ... Hi Bob; Thank you kindly for your prompt reply. I've tried your suggestion. Function MyRoots(a, m As Integer, polish As String) Dim a As Variant, Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) ..............................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) MyRoots = Roots End Function It produces the compile error: "Duplicate declaration in current scope" with reference to the "a" declaration in: Dim a As Variant, Roots As Variant Any suggestion ?? Regards. "Bob Phillips" wrote: I am not clear what your code is doing, especially the ,,, my code ... bits, but your array declaration is definitely wrong. Try this Function MyRoots(a, m As Integer, polish As String) Dim a As Variant, Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) For j = 1 To m + 1 ad(j, 1) = a(j, 1) ad(j, 2) = a(j, 2) Next j Call Laguer(ad, j, x, its) Roots(j, 1) = x(1) Roots(j, 2) = x(2) MyRoots = Roots End Function -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "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. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Bob;
Thanks again. I've done the correction: Function MyRoots (a As Variant, m As Integer, polish As String) Dim Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) ' ..............................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) MyRoots = Roots End Function The array function MyRoots() returns all zeros (same as was posted originally). It seems to me that by declaring the incoming array "a" using: ReDim a(m+1,2) it sets all elements of matrix "a" to 0.0. The Immediate Window for MyRoots() confirms that. I even tried: ReDim Preserve a(m+1,2) with no change. (If you prefer, I would be glad to post or send you the function MyRoots() and its sub Laguer() code. Total ~ 40 lines.) Regards. "Bob Phillips" wrote: Sorry, missed the parameter Function MyRoots(a As Variant, m As Integer, polish As String) Dim Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) ' ..............................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) MyRoots = Roots End Function -- __________________________________ HTH Bob "monir" wrote in message ... Hi Bob; Thank you kindly for your prompt reply. I've tried your suggestion. Function MyRoots(a, m As Integer, polish As String) Dim a As Variant, Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) ..............................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) MyRoots = Roots End Function It produces the compile error: "Duplicate declaration in current scope" with reference to the "a" declaration in: Dim a As Variant, Roots As Variant Any suggestion ?? Regards. "Bob Phillips" wrote: I am not clear what your code is doing, especially the ,,, my code ... bits, but your array declaration is definitely wrong. Try this Function MyRoots(a, m As Integer, polish As String) Dim a As Variant, Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) For j = 1 To m + 1 ad(j, 1) = a(j, 1) ad(j, 2) = a(j, 2) Next j Call Laguer(ad, j, x, its) Roots(j, 1) = x(1) Roots(j, 2) = x(2) MyRoots = Roots End Function -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "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. |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello;
1) It appears that the issue is a bit more difficult than I initially thought. The latest version of the procedure is provided below. It returns #VALUE! to cells I11:J13, which in all probabilities is the result of incorrect declarations of the arrays. Notice that I commented out the declaration ReDim a(m + 1, 2) in Function MyRoots(), otherwise it would re-set all elements of the incoming matrix "a" to 0.0 and the array function would return 0.0s to cells I11:J13. 2) Here's the latest version: cell B8::3 cell B9: myTrue cells B11:C14 numerical values cells I11:J13:: array function {=MyRoots(B11:C14, B8, B9)} Function MyRoots (a As Variant, m As Integer, polish As String) Dim Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ' ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) ' ..............................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) 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 3) The following article deals specifically with the issue at hand: http://www.cpearson.com/Excel/Passin...ningArrays.htm The difficulty in the article is two folds. First: the article deals with passing and returning multi-dimensional arrays but it is written for the experts in VBA, and second: the described procedure deals with Subroutines calling Functions, and not the other way around! The general theme in the article, however, appears to be that dynamic arrays MUST be used. But what if the function is calling the subroutine ?? 4) If it helps, I would be glad to post or email the entire Function MyRoots() and Sub Laguer() (total ~ 40 lines), together with the w/s input values and the expected returned results. Thank you kindly. "monir" wrote: Hi Bob; Thanks again. I've done the correction: Function MyRoots (a As Variant, m As Integer, polish As String) Dim Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) ' ..............................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) MyRoots = Roots End Function The array function MyRoots() returns all zeros (same as was posted originally). It seems to me that by declaring the incoming array "a" using: ReDim a(m+1,2) it sets all elements of matrix "a" to 0.0. The Immediate Window for MyRoots() confirms that. I even tried: ReDim Preserve a(m+1,2) with no change. (If you prefer, I would be glad to post or send you the function MyRoots() and its sub Laguer() code. Total ~ 40 lines.) Regards. "Bob Phillips" wrote: Sorry, missed the parameter Function MyRoots(a As Variant, m As Integer, polish As String) Dim Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) ' ..............................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) MyRoots = Roots End Function -- __________________________________ HTH Bob "monir" wrote in message ... Hi Bob; Thank you kindly for your prompt reply. I've tried your suggestion. Function MyRoots(a, m As Integer, polish As String) Dim a As Variant, Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) ..............................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) MyRoots = Roots End Function It produces the compile error: "Duplicate declaration in current scope" with reference to the "a" declaration in: Dim a As Variant, Roots As Variant Any suggestion ?? Regards. "Bob Phillips" wrote: I am not clear what your code is doing, especially the ,,, my code ... bits, but your array declaration is definitely wrong. Try this Function MyRoots(a, m As Integer, polish As String) Dim a As Variant, Roots As Variant Dim ad As Variant Dim j As Integer, its As Integer Dim x(2) As Double ReDim a(m + 1, 2) ReDim Roots(m, 2) ReDim ad(m + 1, 2) For j = 1 To m + 1 ad(j, 1) = a(j, 1) ad(j, 2) = a(j, 2) Next j Call Laguer(ad, j, x, its) Roots(j, 1) = x(1) Roots(j, 2) = x(2) MyRoots = Roots End Function -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Array Declaration. | Excel Discussion (Misc queries) | |||
Declaration problem | Excel Programming | |||
VBA Declaration problem | Excel Programming | |||
Array Declaration | Excel Programming | |||
dYNAMIC Array declaration, a small correction in my last thread! | Excel Programming |