RemoveItemFromArray Function:
Remove an Item from an Array
Description:
This function removes any element from an array and then resizes the array.
Syntax:
Call RemoveItemFromArray(ItemArray, ItemElement)
Details:
'--- PARAMETERS: ItemArray: Array, passed by reference, with item to be removed. Array must not be fixed ItemElement: Element to Remove
Example:
<%
'--- EXAMPLE: Dim iCtr Dim aTest() ReDim aTest(2) aTest(0) = "Hello" aTest(1) = "World" aTest(2) = "!" Call RemoveItemFromArray(aTest, 1) for iCtr = 0 to ubound(aTest) Response.Write aTest(ictr) & "<br />" next
'--- Result: ' ' "Hello" ' "!"
%>
ASP Source Code:
<%
Public Sub RemoveItemFromArray(ItemArray, ByVal ItemElement) Dim lCtr Dim lTop Dim lBottom If Not IsArray(ItemArray) Then Err.Raise 13, , "Type Mismatch" Exit Sub End If lTop = UBound(ItemArray) lBottom = LBound(ItemArray) If ItemElement < lBottom Or ItemElement > lTop Then Err.Raise 9, , "Subscript out of Range" Exit Sub End If For lCtr = ItemElement To lTop - 1 ItemArray(lCtr) = ItemArray(lCtr + 1) Next On Error Resume Next ReDim Preserve ItemArray(lTop - lBottom - 1) If Err.number <> 0 Then '--- An error will occur if array is fixed Err.Raise Err.Number, , "You must pass a resizable array to this function" End If End Sub
%>
|