<mySnippets order="rand" ⁄>
<myBlog show="last" ⁄>
<myNews show="rand" ⁄>
<myNews type="cat" ⁄>
<myPhoto order="random" ⁄>
<myAdSense ⁄>
<myQuote order="random" ⁄>
<myContacts ⁄><email ⁄>
<windows live messenger ⁄>
<myCurriculum type="pdf" ⁄>
<myVisitorsMap ⁄>
<% ''' <summary> ''' This class allow us to add elements to an Array ''' </summary> '''<author>pedrocorreia.net</author> Class ArrayRedim 'our auxiliary variable to know the array last valid position, 'this is just to prevent to use always UBound Private count_ 'our array Private arr_content ''' <summary> '''' Initializing Class Method, just like a constructor '''' Happens each time class's initialized ''' </summary> Private Sub Class_Initialize() Count=0 arr_content=Array() End Sub ''' <summary> '''' Terminate Class Method '''' Happens each time class's terminated or out of scope ''' </summary> Private Sub Class_Terminate() Clear End Sub ''' <summary> ''' Private Method ''' ''' Allocate necessary memory to ''' add elements to an array ''' </summary> ''' <param>Number of elements</param> Private Sub Allocate(num) ReDim Preserve arr_content(Count+num) 'set new array length Count=Count+num End Sub ''' <summary> ''' Add Element ''' </summary> ''' <param>Element</param> Public Default Sub AddElement(element) 'allocate one element in our array Allocate 1 'add element to last valid position arr_content(Count-1) = element End Sub ''' <summary> ''' Add Elements ''' </summary> ''' <param>Array Elements</param> Public Sub AddElements (arrElems) Dim start_at start_at=Count if IsArray(arrElems) Then 'pre-allocate all necessary memory Allocate UBound(arrElems) For Each elem In arrElems 'add element arr_content(start_at)=elem 'increment position to where we'll add our element start_at=start_at+1 Next End If End Sub ''' <summary> ''' Clear Resources ''' </summary> Public Sub Clear() Erase arr_content Count=0 End Sub ''' <summary> ''' Get Array ''' </summary> ''' <param>Array</param> Public Property Get ArrayRedim() ArrayRedim = arr_content End Property ''' <summary> ''' Print array content ''' </summary> ''' <returns>String</returns> Public Function ToString() If Count=0 then ToString="EmptyArray<br/>" exit function End If ToString=Join(arr_content,"<br/>") End Function ''' <summary> ''' Getter ''' Number of Elements in Array ''' </summary> ''' <returns>Integer</returns> Public Property Get Count() Count=count_ End Property ''' <summary> ''' Private Method ''' ''' Setter ''' Number of Elements in Array ''' </summary> ''' <param>Integer</param> Private Property Let Count(value) count_=value End Property End Class %>
<!-- #include file ="ArrayRedim.asp" --> <% Dim redim_array Set redim_array = new ArrayRedim redim_array.AddElement "1st Element" redim_array.AddElement "2nd Element" redim_array.AddElement "3rd Element" redim_array "4th Element" 'Print array content Response.Write redim_array.ToString 'Clear Array redim_array.Clear 'Print array content Response.Write redim_array.ToString Response.Write "<br/><br/>" 'add a few more elements redim_array "5th Element" redim_array "6th Element" redim_array "7th Element" 'Print array content, don't forget that 'we previously cleared our array Response.Write redim_array.ToString Response.Write "<br/><br/>" 'let's just add a few more elements 'only this time we'll add multiple element at the same time 'for that just send an Array variable redim_array.AddElements Array("8th Element","9th Element","10th Element") 'Print array content Response.Write redim_array.ToString 'get a copy of the array to do something else ... dim new_array new_array=redim_array.ArrayRedim 'clear our ArrayRedim object Set redim_array=nothing 'we cleared our object, but since we saved its array 'to another variable, now we can still use it like a regular array Response.Write "<br/>Array Length: " & Ubound(new_array)+1 %>