I am trying to encode url so as the create or build payload and I am confused between the built-in function `ENCODEURL` and a UDF that is supposed to the same (or at least as I think)
Code: Select all
Sub Test_MyEncodeURL_URLEncode_UDFs()
Dim sText As String
sText = "Button1=" & Join(Array(Chr(200), Chr(205), Chr(203)), Empty)
Debug.Print MyEncodeURL(sText)
Debug.Print URLEncode(sText)
End Sub
Function MyEncodeURL(ByVal sText As String) As String
MyEncodeURL = Application.WorksheetFunction.EncodeURL(sText)
End Function
Function URLEncode(ByVal Text As String) As String
Dim Encoded As String, Char As String, CharCode As Integer, i As Long
Encoded = vbNullString
For i = 1 To Len(Text)
CharCode = Asc(Mid(Text, i, 1))
Select Case CharCode
Case 48 To 57, 65 To 90, 97 To 122
Char = Chr(CharCode)
Case 32
Char = "+"
Case Else
Char = "%" & Hex(CharCode)
End Select
Encoded = Encoded & Char
Next i
URLEncode = Encoded
End Function
Although the results are different but I tried both of them in the payload of the request and both worked well. I am confused a little!!