Opening a URL containing a % symbol

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Mitch
Newbie
Posts: 9
Joined: Wed Apr 22, 2020 9:13 pm

Opening a URL containing a % symbol

Post by Mitch » Wed Apr 22, 2020 9:27 pm

I just learned that I can use ExecuteFile> on a url to launch a web page and this would make my code a lot simpler, but how do I put a % symbol in that string without the system assuming its marking a variable?

Previously i was opening a web page by launching the browser, clicking the url line, and "sendtext" to output the address. I wasn't clear on how to use a % outside of notating a variable so when I needed the symbol, i just had a line sending just the % symbol, and the next line would output the next portion of the URL.

Even tried making a variable that would result in a percent symbol but I wasn't successful in making that work. (example Let>percent=%

Let>URL=www.somesite.com/parameter1%percent%par ... parameter3 but that didn't work for reasons that are hopefully obvious to you (and frustrating to me)

Thanks everyone and anyone willing to help me get a clue

Mitch

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1380
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Opening a URL containing a % symbol

Post by Dorian (MJT support) » Thu Apr 23, 2020 8:28 am

I've put together a few examples of using ExecuteFile with URLs containing a %. Hopefully this will give you an idea of how to get around your issue.

Code: Select all

//This works
executefile>https://www.bing.com/search?q=%something

//This works
executefile>https://www.bing.com/search?q=%hello%

//This works
executefile>https://www.bing.com/search?q=%25&%parm%

//It gets more complicated when we add variables
//This doesn't work if there's already a % symbol in the URL...
let>parm=hello
executefile>https://www.bing.com/search?q=%25&%parm%

//..it does if there isn't a %, but of course removes the %
let>parm=hello
executefile>https://www.bing.com/search?q=25&%parm%

//..this works though
let>parm=%hello%
executefile>https://www.bing.com/search?q=25&%parm%

//..but then breaks if there a % in the url
let>parm=%hello%
executefile>https://www.bing.com/search?q=%25&%parm%

//..so we can do this instead
let>parm=%hello%
let>percent=%
executefile>https://www.bing.com/search?q=%percent%25&%parm%

//..adding some more
let>parm=%hello%
let>percent=%
executefile>https://www.bing.com/search?q=%percent%25&%parm%%percent%something%percent%somethingelse%percent%%percent%

//..or just this
let>percent=%
executefile>https://www.bing.com/search?q=%percent%
Yes, we have a Custom Scripting Service. Message me or go here

Mitch
Newbie
Posts: 9
Joined: Wed Apr 22, 2020 9:13 pm

Re: Opening a URL containing a % symbol

Post by Mitch » Thu Apr 23, 2020 1:02 pm

Thank you so much. I will put this to good use. :D

Franklin
Newbie
Posts: 18
Joined: Mon Dec 14, 2015 5:14 pm

Re: Opening a URL containing a % symbol

Post by Franklin » Sun Jul 26, 2020 8:57 pm

Another option is to use VBA functions (like below) to code/decode the URL and pass it on to execute file command

Code Couresty of http://www.freevbcode.com/ShowCode.asp?ID=1512

Code: Select all

Public Function URLEncode(StringToEncode As String, Optional _
   UsePlusRatherThanHexForSpace As Boolean = False) As String

Dim TempAns As String
Dim CurChr As Integer
CurChr = 1
Do Until CurChr - 1 = Len(StringToEncode)
  Select Case Asc(Mid(StringToEncode, CurChr, 1))
    Case 48 To 57, 65 To 90, 97 To 122
      TempAns = TempAns & Mid(StringToEncode, CurChr, 1)
    Case 32
      If UsePlusRatherThanHexForSpace = True Then
        TempAns = TempAns & "+"
      Else
        TempAns = TempAns & "%" & Hex(32)
      End If
   Case Else
         TempAns = TempAns & "%" & _
              Format(Hex(Asc(Mid(StringToEncode, _
              CurChr, 1))), "00")
End Select

  CurChr = CurChr + 1
Loop

URLEncode = TempAns
End Function


Public Function URLDecode(StringToDecode As String) As String

Dim TempAns As String
Dim CurChr As Integer

CurChr = 1

Do Until CurChr - 1 = Len(StringToDecode)
  Select Case Mid(StringToDecode, CurChr, 1)
    Case "+"
      TempAns = TempAns & " "
    Case "%"
      TempAns = TempAns & Chr(Val("&h" & _
         Mid(StringToDecode, CurChr + 1, 2)))
       CurChr = CurChr + 2
    Case Else
      TempAns = TempAns & Mid(StringToDecode, CurChr, 1)
  End Select

CurChr = CurChr + 1
Loop

URLDecode = TempAns
End Function

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts