G
Graeme
Hi All
I call this function to hyperlink typed URLs, but there must surely be a
better way. What I would like is something better to 1) automatically
hyperlink URLs when clicked, and 2) same for Email addresses. Must have been
done many times before more efficiently than this. Please can someone help?
Function LinkURLs(ByVal strInput) 'called from POST button_click
Dim iCurrentLocation
Dim iLinkStart
Dim iLinkEnd
Dim strLinkText
Dim strOutput
iCurrentLocation = 1
Do While InStr(iCurrentLocation, strInput, "http://", 1) <> 0
iLinkStart = InStr(iCurrentLocation, strInput, "http://", 1)
iLinkEnd = InStr(iLinkStart, strInput, " ", 1)
If iLinkEnd = 0 Then iLinkEnd = Len(strInput) + 1
Select Case Mid(strInput, iLinkEnd - 1, 1)
Case ".", "!", "?"
iLinkEnd = iLinkEnd - 1
End Select
strOutput = strOutput & Mid(strInput, iCurrentLocation, iLinkStart -
iCurrentLocation)
strLinkText = Mid(strInput, iLinkStart, iLinkEnd - iLinkStart)
strOutput = strOutput & "<A HREF=""" & strLinkText & """ target=""_blank"">"
& strLinkText & "</A>"
iCurrentLocation = iLinkEnd
Loop
strOutput = strOutput & Mid(strInput, iCurrentLocation)
LinkURLs = strOutput
End Function
Thanks for your assistance
Graeme
I call this function to hyperlink typed URLs, but there must surely be a
better way. What I would like is something better to 1) automatically
hyperlink URLs when clicked, and 2) same for Email addresses. Must have been
done many times before more efficiently than this. Please can someone help?
Function LinkURLs(ByVal strInput) 'called from POST button_click
Dim iCurrentLocation
Dim iLinkStart
Dim iLinkEnd
Dim strLinkText
Dim strOutput
iCurrentLocation = 1
Do While InStr(iCurrentLocation, strInput, "http://", 1) <> 0
iLinkStart = InStr(iCurrentLocation, strInput, "http://", 1)
iLinkEnd = InStr(iLinkStart, strInput, " ", 1)
If iLinkEnd = 0 Then iLinkEnd = Len(strInput) + 1
Select Case Mid(strInput, iLinkEnd - 1, 1)
Case ".", "!", "?"
iLinkEnd = iLinkEnd - 1
End Select
strOutput = strOutput & Mid(strInput, iCurrentLocation, iLinkStart -
iCurrentLocation)
strLinkText = Mid(strInput, iLinkStart, iLinkEnd - iLinkStart)
strOutput = strOutput & "<A HREF=""" & strLinkText & """ target=""_blank"">"
& strLinkText & "</A>"
iCurrentLocation = iLinkEnd
Loop
strOutput = strOutput & Mid(strInput, iCurrentLocation)
LinkURLs = strOutput
End Function
Thanks for your assistance
Graeme