about dynamic arrays and objects

Results 1 to 2 of 2

Thread: about dynamic arrays and objects

  1. #1
    Join Date
    Dec 1969

    Default about dynamic arrays and objects

    I´ve found this class :<BR><BR>Class DynamicArray<BR> &#039;************** Properties **************<BR> Private aData<BR> &#039;****************************************<BR> <BR> &#039;*********** Event Handlers *************<BR> Private Sub Class_Initialize()<BR> Redim aData(0)<BR> End Sub<BR> &#039;****************************************<BR> <BR> &#039;************ Property Get **************<BR> Public Property Get Data(iPos)<BR> &#039;Make sure the end developer is not requesting an<BR> &#039;"out of bounds" array element<BR> If iPos &#060; LBound(aData) or iPos &#062; UBound(aData) then<BR> Exit Property &#039;Invalid range<BR> End If<BR><BR> Data = aData(iPos)<BR> End Property<BR><BR> Public Property Get DataArray()<BR> DataArray = aData<BR> End Property<BR> &#039;****************************************<BR> <BR> &#039;************ Property Let **************<BR> Public Property Let Data(iPos, varValue)<BR> &#039;Make sure iPos &#062;= LBound(aData)<BR> If iPos &#060; LBound(aData) Then Exit Property<BR><BR> If iPos &#062; UBound(aData) then<BR> &#039;We need to resize the array<BR> Redim Preserve aData(iPos)<BR> aData(iPos) = varValue<BR> Else<BR> &#039;We don&#039;t need to resize the array<BR> aData(iPos) = varValue<BR> End If<BR> End Property<BR> &#039;****************************************<BR> <BR><BR> &#039;************** Methods *****************<BR> Public Function StartIndex()<BR> StartIndex = LBound(aData)<BR> End Function<BR><BR> Public Function StopIndex()<BR> StopIndex = UBound(aData)<BR> End Function<BR><BR> Public Sub Delete(iPos)<BR> &#039;Make sure iPos is within acceptable ranges<BR> If iPos &#060; LBound(aData) or iPos &#062; UBound(aData) then<BR> Exit Sub &#039;Invalid range<BR> End If<BR><BR> Dim iLoop<BR> For iLoop = iPos to UBound(aData) - 1<BR> aData(iLoop) = aData(iLoop + 1)<BR> Next<BR><BR> Redim Preserve aData(UBound(aData) - 1)<BR> End Sub<BR> &#039;****************************************<BR> End Class<BR><BR>..But when I tried to set an object :<BR>class b<BR> public b<BR>end class<BR><BR>set a = new DynamicArray<BR>set a.data(1) = new b<BR><BR>... it really went wrong!<BR>Can someone tell me how to initiate a object in the array existing in the Dynamic object?

  2. #2
    Join Date
    Dec 1969

    Default Yeah, a bug in that code!

    As coded, that class will *ONLY* handle non-object array elements.<BR><BR>For starters, none of the places where it puts data into the array or takes it out use the SET keyword!<BR><BR>You *can* write a class that will handle mixed objects and non-objects in a dynamic array, but it&#039;s probably not a good idea.<BR><BR>I&#039;d just have two classes, one as is and the other that handles only objects and use Property Set (instead of Property Let) and then uses Set for all the elements.<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts