I have to open a browser and provide it a URL to navigate to. A portion of it needs to be URL Encoded (aka Percent Encoded), because it is a re-direct URL being passed along as a parameter to a login URL, and it also has parameters of its own.
I've tried the solution below (it presumes that MSScript.ocx is registered on the machine) and it works great when running from the IDE, which in my case is PB2017R2 Build 1769. There only seems to be a 32 bit version of this ocx however, so when a 64 bit executable was created the ConnectToNewObject function started failing with a return code of -3.
Does anyone know of an alternative way to do URL Encoding from within PB code that will work in a 64 bit exe?
OleObject lnv_MSScript
lnv_MSScript = Create OleObject
// Create a script object to use for URL Encoding/Decoding
$PBExportHeader$nc_urlencode.sru
forward
global type nc_urlencode from nonvisualobject
end type
end forward
global type nc_urlencode from nonvisualobject
end type
global nc_urlencode nc_urlencode
forward prototypes
public function string of_nbr2hex (unsignedlong aul_number, integer ai_digit)
public function long of_hex2nbr (string as_hex)
public function string of_urlencode (string as_string)
end prototypes
public function string of_nbr2hex (unsignedlong aul_number, integer ai_digit);
ULong lul_temp0, lul_temp1
Char lc_ret
If ai_digit > 0 Then
lul_temp0 = Abs(aul_number / (16 ^ (ai_digit - 1)))
lul_temp1 = lul_temp0 * (16 ^ (ai_digit - 1))
If lul_temp0 > 9 Then
lc_ret = Char(lul_temp0 + 55)
Else
lc_ret = Char(lul_temp0 + 48)
End If
Return lc_ret + of_Nbr2Hex(aul_number - lul_temp1, ai_digit - 1)
End If
Return ""
end function
public function long of_hex2nbr (string as_hex);
Integer li_work
String ls_code, ls_hex = '123456789ABCDEF'
Long ll_rc, ll_lp
ls_code = Reverse(Upper(as_hex))
ll_rc = len(ls_code)
For ll_lp = 1 To ll_rc
li_work = li_work + Pos(ls_hex, Mid(ls_code, ll_lp, 1), 1) * (16^(ll_lp - 1))
Next
Return li_work
end function
public function string of_urlencode (string as_string);
String ls_Result, ls_Character
Integer li_Ascii, li_CurChr
li_CurChr = 1
Do Until li_CurChr - 1 = Len(as_string)
ls_Character = Mid(as_string, li_CurChr, 1)
li_Ascii = AscA(ls_Character)
Choose Case li_Ascii
Case 48 To 57, 65 To 90, 97 To 122
// Numbers 0-9, Uppercase A-Z, Lowercase a-z
ls_Result += ls_Character
Case Else
ls_Result = ls_Result + "%" + &
of_Nbr2Hex(AscA(ls_Character), 2)
End Choose
li_CurChr ++
Loop
Return ls_Result
end function
on nc_urlencode.create
call super::create
TriggerEvent( this, "constructor" )
end on
on nc_urlencode.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on