Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Nested arrays
Message
From
14/06/1998 09:40:29
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00107969
Message ID:
00107990
Views:
16
>This time with formatting...
>
>Can an array element be another array?
>
>I.E. Is this possible (view from the debugger's "watch" window)
>---------------------------------------------------
><strong>=== aSampleArray (Array)</strong>
> +- element1 'element one contents'
> +- element2 'element two contents'
> +- element3 (Array)
>    +- sub_el1 'sub-element one contents'
>    +- sub_el2 'sub-element two contents'
>    +- sub_el3 'sub-element three contents'
> ---------------------------------------------------
>
>
>If so, how do I assign the array to an array element?
>
> TIA

If you're looking for the functionality from Clipper, no. If you want to go to the trouble of embedding object pointers in array elements and then drilling down when an object pointer is encountered, yes it can be done, but the overhead is tremendous. No sparse array capability either unless you disallow nulls as legal values when working with arrays and stick nulls in explicitly where sparse..

Using objects-based pointers, you could do something like:
DEFINE CLASS EmbedArray AS Custom
   DECLARE iaEmbedded[1]
   iaEmbedded[1] = NULL
   inNumElements = 0
   inLastElementRef = -1
   PROCEDURE SizeArray
      LPARAMETER tnElements
      DIMENSION This.iaEmbedded[MAX(tnElements,1)]
      IF tnElements > This.inNumElements
         LOCAL nCtr
         FOR nCtr = This.inNumElements + 1 TO tnElements
            This.iaEmbedded[nCtr] = NULL
         ENDFOR
      ENDIF
      This.inNumElements = tnElements
      RETURN .T.
   ENDPROC
   PROCEDURE SetElement
   LPARAMETER tuValue,tnElement
      LOCAL lReturn
      lReturn = .F.
      IF TYPE('tnElement') # 'N'
         tnElement = MAX(This.inLastElementRef + 1,0)
      ENDIF
      IF BETWEEN(tnElement,1,This.inNumElements)
         This.iaEmbedded[tnElement] = tuValue
          lReturn = .T.
      ELSE
         tnElement = -1
         lReturn = .F.
      ENDIF
      This.inLastElementRef = tnElement
      RETURN lReturn
   ENDPROC
   FUNCTION GetElement
   LPARAMETER tnElement
      LOCAL uReturn
      uReturn = .F.
      IF TYPE('tnElement') # 'N'
         tnElement = MIN(MAX(This.inLastElementRef + 1,0),This.inNumElements + 1)
      ENDIF
      IF BETWEEN(tnElement,1,This.inNumElements)
         uReturn = This.iaEmbedded[tnElement] 
         This.inLastElementRef = tnElement
      ELSE
         tnElement = -1
         uReturn = NULL
      ENDIF
      This.inLastElementRef = tnElement
      RETURN uReturn
   ENDFUNC
ENDDEFINE

*Create an array
DECLARE aSampleArray(3)
   aSampleArray[1] = 'string value'
   aSampleArray[2] = 42
   aSampleArray[3] = CREATEOBJECT('EmbedArray')
   aSampleArray(3).SizeArray(3)
   aSampleArray(3).SetElement('A new string value',1)
   aSampleArray(3).SetElement(42)
   aSampleArray(3).SetElement(CREATEOBJ('EmbedArray'))
You get the idea...probably not worth the effort, since getting embedded arrays out involves checking each array element to see if it's an object of type EmbedArray, etc. It does allow yu to assign objects of type EmbedArray to variables, which can have embedded EmbedArray objects, etc.

Ed
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform