View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
BEETAL[_2_] BEETAL[_2_] is offline
external usenet poster
 
Posts: 3
Default UBound function does not work

I forgot to address the question to the Experts.
Dear Experts, Please help.

Thank you so much for taking time to read the post. More thanks for
solutions,in advance.

"BEETAL" wrote:

I have defined two matrices InMatrix1 and InMatrix2 on a spredsheet by names.
The programme does not execute.
When I type UBound in the VBEditor, there is no prompt for the UBound word
after I press shift+spacebar.

What is the problem?
Function MatrixMult(InMatrix1 As Variant, InMatrix2 As Variant) As Variant

'generic matrix multiplication engine, pure BASIC code
Dim OutMatrix()
Dim i As Integer, k As Integer
Dim j As Integer
Dim Sum As Integer
ReDim OutMatrix(1 To UBound(InMatrix1, 1), 1 To UBound(InMatrix2, 2))

Application.Volatile 'force recalculation with spreadsheet

For i = 1 To UBound(InMatrix1, 1) 'rows of inmatrix1
For j = 1 To UBound(InMatrix2, 2) 'cols of inmatrix2
Sum = 0
For k = 1 To UBound(InMatrix1, 2)
Sum = Sum + InMatrix1(i, k) * InMatrix2(k, j)
Next
OutMatrix(i, j) = Sum
Next
Next

MatrixMult = OutMatrix

End Function