| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Functions
The following is just a list of functions that you can use to perform certain tasks through out your applications.
Calculate Age This function will calculate a persons age based on the two dates passed to it. Code:
Function CalculateAge(Date1, Date2)
bornDate = CDate(Date1)
futureDate = CDate(Date2)
if(Month(futureDate) < Month(bornDate) OR Month(futureDate) = Month(bornDate) AND Day(futureDate) < Day(bornDate)) Then
age = Year(futureDate) - Year(bornDate) - 1
else
age = Year(futureDate) - Year(bornDate)
end if
CalculateAge = age
End Function
Word Wrap Function This function will print a certain number of characters per line of the string passed, depending on the integer value passed. Code:
Function LineWrap(sString, iInterval) lFinalLen = Len(sString) Do Until lPos >= lFinalLen If iPosCounter = iInterval Then iPosCounter = 0 For lBeginPos = lPos To 0 Step -1 If Mid(sString, lBeginPos, 1) = Chr(32) Then Exit For Next For lEndPos = lPos To lFinalLen If Mid(sString, lEndPos, 1) = Chr(32) Then Exit For Next iWordLen = (lEndPos - 1) - (lBeginPos + 1) iWordPos = lPos - (lBeginPos + 1) dWrapThresh = iWordLen / 2 If lEndPos > Len(sString) Then Exit Do If iWordPos >= dWrapThresh Then sString = Left(sString, lEndPos) & "<br>" & Right(sString, lFinalLen - lEndPos) Else sString = Left(sString, lBeginPos) & "<br>" & Right(sString, lFinalLen - lBeginPos) End If lFinalLen = Len(sString) End If iPosCounter = iPosCounter + 1 If lPos > 0 Then If Mid(sString, lPos, 2) = "<br>" Then iPosCounter = 0 lPos = lPos + 1 Loop LineWrap = sString End Function Proper Case Function This function will print a supplied string in Proper Case The first letter of every word is capitalized Code:
Function PCase(sValue)
iPos = 1
Do While InStr(iPos, sValue, " ", 1) <> 0
iSpace = InStr(iPos, sValue, " ", 1)
sTemp = sTemp & UCase(Mid(sValue, iPos, 1))
sTemp = sTemp & LCase(Mid(sValue, iPos + 1, _
iSpace - iPos))
iPos = iSpace + 1
Loop
sTemp = sTemp & UCase(Mid(sValue, iPos, 1))
sTemp = sTemp & LCase(Mid(sValue, iPos + 1))
PCase = sTemp
End Function
Feel free to private message me with any functions you might need and I will continue to update this thread. Last edited by Memnoch : April 5th, 2004 at 03:14 PM. |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Functions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|