View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Nigel[_2_] Nigel[_2_] is offline
external usenet poster
 
Posts: 735
Default Storing and retrieving 3-D arrays in/from workbook names

??

--

Regards,
Nigel




"Alan Beban" wrote in message
...
The following two procedures (1) save the elements of a 3-D array in
workbook names, and (2) Load a 3-D array from the workbook names in which
they were stored. They depend on other functions in the freely
downloadable file at
http://home.pacbell.net/beban, but have not yet been
uploaded to that file.

Alan Beban

Sub Save3DInNames(inputArray, arrayName)
'This procedure stores the values from
'a 3-D array into workbook names. Visualizing
'the 3-D array as a rectangular solid
'sitting on the xy-plane (analogous to the
'rows and columns plane of a worksheet),
'the contents of the two-D arrays in the xy-plane
'and the planes parallel to it at each level of the
'third dimension are stored in workbook names
'from where they can be retrieved after the procedure
'has ended. E.g., if the array name were "myArray", the
'planes would be stored in myArrayPlaneXY0,
'myArrayPlaneXY1, etc., where the number at the end
'of the name refers to the offset of the respective plane
'from the xy-plane.

Dim i As Long

'Insure that the first input parameter refers to an array
If Not TypeName(inputArray) Like "*()" Then
MsgBox "This procedure requires that the first " & _
"input parameter refer to an array"
Exit Sub
End If

'And insure that is 3-D
If Not ArrayDimensions(inputArray) = 3 Then
MsgBox "The array must be three-dimensional"
Exit Sub
End If

'Store the planes
For i = 0 To UBound(inputArray, 3) - LBound(inputArray, 3)
Names.Add Name:=arrayName & "PlaneXY" & i, _
RefersTo:=TwoD(inputArray, "xy", i)
Next
End Sub

Function Load3DFromNames(Base As Boolean, _
arrayName As String, firstPlane)
'This function loads a 3-D array from where
'it was stored in workbook names. It is called like
'w = Load3DFromNames(0, "myArray", [myArrayPlaneXY0])

Dim iName, x As String, k As Long

'Insure that 3rd input parameter is an array
If Not TypeName(firstPlane) Like "*()" Then
MsgBox "The third input parameter must be an array"
Exit Function
End If

'And that it is 3-D
If Not ArrayDimensions(firstPlane) = 2 Then
MsgBox "The third input parameter must be a 3-D array"
Exit Function
End If

k = 0 '<----Counter for relevant names
For Each iName In Names
If iName.Name Like arrayName & "Plane*" Then k = k + 1
Next

If k = 0 Then
MsgBox "There are no workbook names " & _
"like """ & arrayName & "" & "Plane*"""
Exit Function
End If

'Convert xy-plane to 3D
p1 = ThreeD([firstPlane])

'Add other level parallel xy-planes
For i = 1 To k - 1
AddPlane p1, Evaluate(arrayName & "PlaneXY" & i)
Next

'Insure that loaded 3-D array has the specified base
ConvertBase p1, -Base, -Base, -Base

'Return loaded 3D array
Load3DFromNames = p1
End Function