'********************************************************************
'*
'* Function ResizeOnDelete
'*
'* Author: NetworkAdminKB.com
'* Created: 2006-01-07
'* Modified: 2006-01-07
'*
'* Purpose: Return an array with the specified value removed and
'* with one less element in the size of the array.
'*
'* Input: aryAny = The array to have the element removed
'* anyVar = The variable to remove from the array.
'* If this is Empty the element at position
'* 0 is returned.
'* blnCase = A boolean indcating if a Case Sensitive
'* search should be done on the array.
'* True = Case Sensitive
'* False = Case In-Sensitive
'* blnOrder = A boolean indcating to maintain the same ordering.
'* True = Maintain the same ordering as in the
'* original array.
'* False = Do not maintain the same ordering (faster)
'* blnVerbose = A Boolean indicating if error messages should
'* be displayed.
'* True = Display Error Messages
'* False = Do NOT Display Error Messages
'*
'* Output: Returns the array with the specified value removed and
'* with one less element in the size of the array.
'* Return Empty if the last Element is removed.
'* Return the original array if the element is not found.
'* Return the original variable if the array passed is
'* not actually an array.
'*
'* Notes: Maintaining the same ordering as the original array introduces
'* verhead of BigO(n).
'*
'* Calls:
'* FastIndexFind
'********************************************************************
Function ResizeOnDelete(ByVal aryAny, ByVal anyVar, ByVal blnCase, ByVal blnOrder,_
ByVal blnVerbose)
'Version: 1.0 2006-01-07
Dim intUBound, intIndex
If IsArray(aryAny) Then
intUBound = UBound(aryAny)
If intUBound = 0 Then
aryAny = Empty
Else
If IsEmpty(anyVar) Then
intIndex = 0
Else
intIndex = FastIndexFind(aryAny, anyVar, blnCase)
End If 'IsEmpty(anyVar)
If IsEmpty(intIndex) Then
If blnVerbose Then
Wscript.Echo "ResizeOnDelete", _
"Error: The anyVar parameter passed was not an found in the array."
End If 'blnVerbose
Else
If blnOrder Then
'Copy all the elements down one position in the array.
For x = intIndex To intUBound - 1
aryAny(x) = aryAny(x+1)
Next 'x
Else
'Copy the last element to the position to be removed
aryAny(intIndex) = aryAny(intUBound)
End If 'blnOrder
'Resize the array.
ReDim Preserve aryAny(intUBound - 1)
End If 'IsEmpty(intIndex)
End If 'UBound(aryAny) = 0
Else
If blnVerbose Then
Wscript.Echo "ResizeOnDelete", _
"Error: The aryAny parameter passed is not an array."
End If 'blnVerbose
End If 'IsArray(aryAny)
ResizeOnDelete = aryAny
End Function 'ResizeOnDelete
Article ID: 416, Created On: 9/25/2011, Modified: 9/25/2011