View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Return Array from Function

Sub GetCoordsj()
Dim aC as Variant
Dim bHflip As Boolean, bVflip As Boolean
Dim nBegin As Long, nEnd As Long
Dim shp As Shape

Set shp = ActiveSheet.Shapes(Selection.Name)

aC = fGetCoord(shp)
bHflip = shp.HorizontalFlip
bVflip = shp.VerticalFlip

If bHflip = bVflip Then
If bVflip = False Then
'down to right
nBegin = 1: nEnd = 4
Else
'up to left
nBegin = 4: nEnd = 1
End If
ElseIf bHflip = False Then
'up to right
nBegin = 3: nEnd = 2
Else
'down to left
nBegin = 2: nEnd = 3
End If
MsgBox "Begin X,Y " & aC(nBegin, 1) & ", " & aC(nBegin, 2) & Chr(13) _
& "End X,Y " & aC(nEnd, 1) & ", " & aC(nEnd, 2)
End Sub

Public Function fGetCoord(shp as Shape) as Variant
Dim aC(1 to 4, 1 to 2) as Double
With shp
aC(1, 1) = .Left: aC(1, 2) = .Top
aC(2, 1) = .Left + .Width: aC(2, 2) = .Top
aC(3, 1) = .Left: aC(3, 2) = .Top + .Height
aC(4, 1) = .Left + .Width: aC(4, 2) = .Top + .Height

End With
fGetCoord = aC
end Function


--
Regards,
Tom Ogilvy


"Zone" wrote in message
...
I want to use the following subroutine as a function which will return
array aC. How would I declare it? Also, how would a sub then call the
function and display the results in a message box? TIA, James
Sub GetCoordsj()
Dim aC(1 To 4, 1 To 2) As Double
Dim bHflip As Boolean, bVflip As Boolean
Dim nBegin As Long, nEnd As Long
Dim shp As Shape

Set shp = ActiveSheet.Shapes(Selection.Name)
With shp
aC(1, 1) = .Left: aC(1, 2) = .Top
aC(2, 1) = .Left + .Width: aC(2, 2) = .Top
aC(3, 1) = .Left: aC(3, 2) = .Top + .Height
aC(4, 1) = .Left + .Width: aC(4, 2) = .Top + .Height

bHflip = .HorizontalFlip
bVflip = .VerticalFlip
End With

If bHflip = bVflip Then
If bVflip = False Then
'down to right
nBegin = 1: nEnd = 4
Else
'up to left
nBegin = 4: nEnd = 1
End If
ElseIf bHflip = False Then
'up to right
nBegin = 3: nEnd = 2
Else
'down to left
nBegin = 2: nEnd = 3
End If
' MsgBox "Begin X,Y " & aC(nBegin, 1) & ", " & aC(nBegin, 2) & Chr(13) _
' & "End X,Y " & aC(nEnd, 1) & ", " & aC(nEnd, 2)
End Sub