View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
LesHurley LesHurley is offline
external usenet poster
 
Posts: 61
Default Re-entrant function

Bob, Dana is using a sub and supplying the data in the procedure. Dana's Tr2
works OK with VBA arrays but not with Range Objects passed from EXCEL as
arguments. Any pair of 3-d vectors are fine for Va and Vb but they must come
from EXCEL. That's what the procedure is for. Please see my opening post
for details. Only one change there that shouldn't matter anyway: change the
Static to Dim on r and c.
Thanks for your help


"Bob Phillips" wrote:

Les,

I tested it and it seemed to work okay.

What is the data that is erroring?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"LesHurley" wrote in message
...
Sorry Bob, that doesn't work any different than before. Still crashes
when
it tries to make the assignment at line 9 (between the two debug.Print ...
ststements).
--
Thanks for your help


"Bob Phillips" wrote:

Function XX(Va, Vb)
Dim CP() As Double
Static r As Integer, c As Integer

Debug.Print TypeName(Va), TypeName(Vb)

r = Selection.Rows.Count
c = Selection.Columns.Count

If r c Then
ReDim CP(3, 1)
Debug.Print "Got to line 8 OK"
CP(1, 1) = Va(2) * Vb(3) - Va(3) * Vb(2)
Debug.Print "Got to line 10 OK"
CP(2, 1) = Va(3) * Vb(1) - Va(1) * Vb(3)
CP(3, 1) = Va(1) * Vb(2) - Va(2) * Vb(1)
Debug.Print r, CP(1, 1), CP(2, 1), CP(3, 1)
XX = Application.Transpose(Application.Transpose(CP))
Else
ReDim CP(1, 3)
CP(1, 1) = Va(2) * Vb(3) - Va(3) * Vb(2)
CP(1, 2) = Va(3) * Vb(1) - Va(1) * Vb(3)
CP(1, 3) = Va(1) * Vb(2) - Va(2) * Vb(1)
Debug.Print r, CP(1, 1), CP(1, 2), CP(1, 3)
XX = CP
End If
End Function


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"LesHurley" wrote in message
...
Several weeks ago I posted a version of this and I thought I had it
solved
with help from this DG - but not so!

xx(j,k) calculates the crossproduct of two 3-dimensional vectors. the
result is returned in either a row or column on the work sheet as
selected
by
the user. Normally the function works ok. It even works ok in
"=xx(xx(i,j),xx(k,l)) when the selection is a row but crashes at line
9,
on
the third pass (Va and Vb are then Variants) when the selection is a
column.
I'm using Option Base 1.

Function XX(Va, Vb)
Debug.Print TypeName(Va), TypeName(Vb)
Static r As Integer, c As Integer

r = Selection.Rows.Count
c = Selection.Columns.Count

Dim CP() As Double
If r c Then
ReDim CP(3, 1)
8 MsgBox "Got to line 8 OK"
9 CP(1, 1) = Va(2) * Vb(3) - Va(3) * Vb(2)
10 MsgBox "Got to line 10 OK"
CP(2, 1) = Va(3) * Vb(1) - Va(1) * Vb(3)
CP(3, 1) = Va(1) * Vb(2) - Va(2) * Vb(1)
Debug.Print r, CP(1, 1), CP(2, 1), CP(3, 1)
Else
ReDim CP(1, 3)
11 CP(1, 1) = Va(2) * Vb(3) - Va(3) * Vb(2)
CP(1, 2) = Va(3) * Vb(1) - Va(1) * Vb(3)
CP(1, 3) = Va(1) * Vb(2) - Va(2) * Vb(1)
Debug.Print r, CP(1, 1), CP(1, 2), CP(1, 3)
End If
XX = CP
End Function

Can anyone help?

--
Thanks for your help