Search Tools Links Login

ServerDotURLEncode


Visual Basic 6, or VB Classic

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

Original Author: Rick Conklin

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)

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

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 108 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.