JS -> VB6

Status
Not open for further replies.

akolchin

Seniorius Lurkius
2
I ran into the same problem... escape is done by Server.URLEncode
There is no built-in function for unescape (since the Session object does it automatically). In any case, if you need it, I use this handy little piece of code I found:

Function URLDecode(Byval What)
'URL decode function
'2001 Antonin Foller, PSTRUH Software, http://www.pstruh.cz
Dim Pos, pPos

'replace + to space
What = Replace(What, "+", " ")

On Error Resume Next
Dim Stream: Set Stream = CreateObject("ADODB.Stream")
If Err = 0 Then 'URLDecode using ADODB.Stream, if possible
On Error Goto 0
Stream.Type = 2 'String
Stream.Open

'replace all %XX to character
Pos = Instr(1, What, "%")
pPos = 1
Do While Pos > 0
Stream.WriteText Mid(What, pPos, Pos - pPos) + _
Chr(CLng("&H" & Mid(What, Pos + 1, 2)))
pPos = Pos + 3
Pos = Instr(pPos, What, "%")
Loop
Stream.WriteText Mid(What, pPos)

'Read the text stream
Stream.Position = 0
URLDecode = Stream.ReadText

'Free resources
Stream.Close
Else 'URL decode using string concentation
On Error Goto 0
'UfUf, this is a little slow method.
'Do not use it for data length over 100k
Pos = Instr(1, What, "%")
Do While Pos>0
What = Left(What, Pos-1) + _
Chr(CLng("&H" & Mid(What, Pos+1, 2))) + _
Mid(What, Pos+3)
Pos = Instr(Pos+1, What, "%")
Loop
URLDecode = What
End If
End Function
 
Status
Not open for further replies.