README.md

December 4, 2022 ยท View on GitHub

ServerDotURLEncode

Description

Used by VB applications that want to lightly (without any additional project references) transform unsafe characters into web-friendly URL Encoded text.

More Info

A string. Just start a new project with two text fields (Text1 and Text2) and paste the code into the form.

The URLEncoded version of that string. (Typically used when sending QueryString of Form data to web pages)

Submitted On
ByRick Conklin
LevelIntermediate
User Rating4.5 (18 globes from 4 users)
CompatibilityVB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
CategoryString Manipulation
WorldVisual Basic
Archive File

Source Code

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