Listing 12 UrlEncode
' Encode parameter name or value that will go into the query string of the URL. Public Function UrlEncode(ByVal vsVal) As String Const lsOK_CHARS$ = _ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.*" Dim llIdx As Long Dim lsChar As String llIdx = 1 Do lsChar = Mid$(vsVal, llIdx, 1) 'is the current character is a space, change it to a "+" If lsChar = " " Then Mid$(vsVal, llIdx, 1) = "+" 'is the current character OK, or does it need to be encoded? ElseIf InStr(1, lsOK_CHARS, lsChar) <= 0 Then vsVal = Mid$(vsVal, 1, llIdx - 1) & _ "%" & Right$("0" + Hex(Asc(lsChar)), 2) & Mid$(vsVal, llIdx + 1) llIdx = llIdx + 2 End If llIdx = llIdx + 1 Loop While (llIdx <= Len(vsVal)) UrlEncode = vsVal End Function