Hey, check out the following function. I did some testing on it and I think it could be a little faster. Now I don't know what else I can do to make it faster. I tried replacing the StrConv function to CopyMemoryStringToAny, and that did VERY LITTLE difference on a 100000 loop (like 100 ms at the most). Is there a better way to do it all together?
VB Code:
Public Function UrlEncode(ByVal urlText As String) As String Dim ANSI() As Byte Dim ASCII As Long Dim encText As String Dim I As Long On Error GoTo UrlEncode_Error ANSI = StrConv(urlText, vbFromUnicode) For I = 0 To UBound(ANSI) ASCII = (ANSI(I) + 2) Mod 256 'Roll over back to 0 past 255, else HEX and CHR won't work Select Case ASCII Case 48 To 57, 65 To 90, 97 To 122 'Letters and Numbers encText = encText & Chr(ASCII) Case 32 'Spaces encText = encText & "+" Case 0 To 16 'Low Hex characters encText = encText & "%0" & Hex(ASCII) Case Else 'Special Characters encText = encText & "%" & Hex(ASCII) End Select Next I UrlEncode = encText Exit Function UrlEncode_Error: MsgBox "Error #:" & Err.Number & vbCrLf & "Procedure [UrlEncode] of Module [mNetFunctions]" & vbCrLf & "Description: " & Err.Description, vbOKOnly, "Error Handling" End Function




Reply With Quote