'This function returns a copy of the array with all instances of the specified value removed
function removeValueFromArray(byval arrayName, valueToRemove)
amountFound = 0 'keeps track of how many it found so that it knows what size to redim the array at the end
topIndex = ubound(arrayName) 'hold the value of the ubound in a variable so that you can decrement it when you find the value to remove
for i = 0 to ubound(arrayName)
if i > topIndex then 'this keeps the loop from checking past the topIndex. keeps the loop from being infinite when the last value
exit for ' exit the loop when you have reached the end of the checked values
end if
if arrayName(i) = valueToRemove then
topIndex = topIndex - 1 'decrement the topIndex when you shift down so that it doesn't check the duplicated values at the end of the array
amountFound = amountFound + 1 ' the value has been found so increment
for j = i to (ubound(arrayName) - 1) 'shift the array values left to overwrite the value to remove
arrayName(j) = arrayName(j + 1)
next
'if the next element was equal to valueToRemove you have to go back and get rid of it too
if arrayName(i) = valueToRemove then
i = i - 1 ' this gets incremented at the beginning of the loop so don't worry about negative values
end if
end if
next
redim preserve arrayName(ubound(arrayName) - amountFound)
removeValueFromArray = arrayName
end function
Function shortenText(text, length, append)
if (Len(text) > length) then 'shorten if greater than length
descriptionArr = Split(text, " ") 'split words into an array
text = ""
for i = 0 to UBound(descriptionArr)
descriptionWord = descriptionArr(i)
if (Len(descriptionWord) + Len(text) + 1 <= length) then 'if new word plus sentence being put together is shorten than length'
text = text & descriptionWord & " "
else
exit for
end if
next
if append <> "" then
text = text & append
end if
shortenText = text
else
shortenText = text
end if
End Function
function areArraysEqual(byval array1, byval array2)
areTheyEqual = true
if ubound(array1) <> ubound(array2) then
areTheyEqual = false
else
for i = 0 to ubound(array1)
if (array1(i) <> array2(i)) then
areTheyEqual = false
end if
next
end if
areArraysEqual = areTheyEqual
end function
'From http://www.4guysfromrolla.com/aspfaqs/ShowFAQ.asp?FAQID=114
Function Shuffle( inArray, needed )
' find out how many input elements there are...
incnt = UBound( inArray )
' then create the output array to be the size
' requested via the "needed" argument
dim outArray
redim outArray( needed )
' now we will select the number of values
' specified as "needed"...
For i = 0 To needed
' choose a random number from 1 to our
' current input array usage size...
choose = Int( incnt * Rnd(1) )
' put that chosen element into the next
' slot in the output array...
outArray( i ) = inArray( choose )
' here's the tricky part: Since we just
' used the "choose" element, we don't need
' it any more...we replace it with the last
' element of the in-use part of the array!
inArray( choose ) = inArray( incnt )
' and then we (effectively) shrink the array!
' Next time through the loop, there will be
' one fewer elements in the array to choose
' from...because we have (effectively) deleted
' the one just chosen!
incnt = incnt - 1
Next
' return the shuffled output
Shuffle = outArray
End Function
<%
'Counts number of occurrences of a certain char(s) in a string, returns number
Function CharCount(SourceString, CharsToFind)
LengthOfSourceString = Len(SourceString)
LengthOfCharsToFind = Len(CharsToFind)
If LengthOfCharsToFind >= LengthOfSourceString Then
If LCase(CharsToFind) = LCase(SourceString) Then
CharCount = 1
Else
CharCount = 0
End If
Exit Function
Else
LoopLength = (LengthOfSourceString - LengthOfCharsToFind) + 1
OccurrenseCounter = 0
For i=1 to LoopLength
CurrentSample = Mid(SourceString,i,LengthOfCharsToFind)
If LCase(CurrentSample) = LCase(CharsToFind) Then
OccurrenseCounter = OccurrenseCounter + 1
Else
End If
Next
CharCount = OccurrenseCounter
End If
End Function
%>