ServerDotURLEncode

Used by VB applications that want to lightly (without any additional project references) transform unsafe characters into web-friendly URL Encoded text.
Inputs
A string. Just start a new project with two text fields (Text1 and Text2) and paste the code into the form.
Returns
The URLEncoded version of that string. (Typically used when sending QueryString of Form data to web pages)
Rate ServerDotURLEncode
(4(4 Vote))
Function ServerDotURLEncode(strBefore As String) As String
Dim strAfter As String
Dim intLoop As Integer
If Len(strBefore) > 0 Then
For intLoop = 1 To Len(strBefore)
Select Case Asc(Mid(strBefore, intLoop, 1))
Case 48 To 57, 65 To 90, 97 To 122, 46, 45, 95, 42 '0-9, A-Z, a-z . - _ *
strAfter = strAfter & Mid(strBefore, intLoop, 1)
Case 32
strAfter = strAfter & "+"
Case Else
strAfter = strAfter & "%" & Right("0" & Hex(Asc(Mid(strBefore, intLoop, 1))), 2)
End Select
Next
End If
ServerDotURLEncode = strAfter
End Function
Private Sub Text1_Change()
Text2 = ServerDotURLEncode(Text1)
End Sub
ServerDotURLEncode Comments
No comments yet — be the first to post one!
Post a Comment