Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Function strCode(ByVal strSource As String, strASCIIEscape As String) As String
' Procedure :   strCode
' Description:  Encode ASCII values into a string.
' Copyright:    Chris Greaves Inc.
' Inputs:       A string, an ASCII escape character.
' Returns:      A transofrmation of the original string.
' Assumes:      None.
' Side Effects: None.
' Tested:       By the calls shown below.
    Dim strReplace As String ' interim value
    Dim strDigits As String ' 3-digit characters extracted as the ASCII code.
    Dim strLeft As String ' previously-treated part of the source string
    Dim strRight As String ' still-to-be-treated part of the source string
    Dim intI As Integer ' pointer to our current position in the source string.
    Dim intOldI As Integer ' last known pointer; used to control the WHILE loop
    intI = InStr(1, strSource, strASCIIEscape) ' Look for the escape character
    While intOldI < intI ' while we are progressing forwards ....
        strReplace = strASCIIEscape ' default in case we find a doubled-esacpe character
        intOldI = intI ' preserve previous-pointer value
        strLeft = Left(strSource, intI - 1) ' obtain what's been done to date.
        strRight = Right(strSource, Len(strSource) - intI - Len(strASCIIEscape) + 1) ' obtain what's to be examined.
        If Mid(strSource, intI + 1, 1) = strASCIIEscape Then ' we must replace the double-escape with a single
            strReplace = strASCIIEscape ' here is where ^^ gets replaced with ^
            strRight = Right(strSource, Len(strSource) - intI - 1) ' and adjust the remnant
        Else
            If strOnly(Mid(strSource, intI + 1, 3), strcDigits) Then ' We have a 3-digit code following the escape character
                strDigits = Mid(strSource, intI + 1, 3) ' here is where ^013 gets replaced with CR
                strReplace = Chr(Val(strDigits))
                strRight = Right(strRight, Len(strRight) - 3)
            Else
            End If
        End If
        strSource = strLeft & strReplace & strRight ' rebuild our working copy ready for the next essay.
        intOldI = intI ' preserve the old pointer value
        intI = InStr(intOldI + 1, strSource, strASCIIEscape) ' and see if there is any more work to be done
    Wend
    strCode = strSource ' when we are done, return our assembled value
'Sub TESTstrCode()
'MsgBox strCode("^216", "^")
'MsgBox strCode("^^", "^")
'MsgBox strCode("abd^^^013def", "^")
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Function strCode(ByVal strSource As String, strASCIIEscape As String) As String
' Procedure :   strCode
' Description:  Encode ASCII values into a string.
' Copyright:    Chris Greaves Inc.
' Inputs:       A string, an ASCII escape character.
' Returns:      A transofrmation of the original string.
' Assumes:      None.
' Side Effects: None.
' Tested:       By the calls shown below.
    Dim strReplace As String ' interim value
    Dim strDigits As String ' 3-digit characters extracted as the ASCII code.
    Dim strLeft As String ' previously-treated part of the source string
    Dim strRight As String ' still-to-be-treated part of the source string
    Dim intI As Integer ' pointer to our current position in the source string.
    Dim intOldI As Integer ' last known pointer; used to control the WHILE loop
    intI = InStr(1, strSource, strASCIIEscape) ' Look for the escape character
    While intOldI < intI ' while we are progressing forwards ....
        strReplace = strASCIIEscape ' default in case we find a doubled-esacpe character
        intOldI = intI ' preserve previous-pointer value
        strLeft = Left(strSource, intI - 1) ' obtain what's been done to date.
        strRight = Right(strSource, Len(strSource) - intI - Len(strASCIIEscape) + 1) ' obtain what's to be examined.
        If Mid(strSource, intI + 1, 1) = strASCIIEscape Then ' we must replace the double-escape with a single
            strReplace = strASCIIEscape ' here is where ^^ gets replaced with ^
            strRight = Right(strSource, Len(strSource) - intI - 1) ' and adjust the remnant
        Else
            If strOnly(Mid(strSource, intI + 1, 3), strcDigits) Then ' We have a 3-digit code following the escape character
                strDigits = Mid(strSource, intI + 1, 3) ' here is where ^013 gets replaced with CR
                strReplace = Chr(Val(strDigits))
                strRight = Right(strRight, Len(strRight) - 3)
            Else
            End If
        End If
        strSource = strLeft & strReplace & strRight ' rebuild our working copy ready for the next essay.
        intOldI = intI ' preserve the old pointer value
        intI = InStr(intOldI + 1, strSource, strASCIIEscape) ' and see if there is any more work to be done
    Wend
    strCode = strSource ' when we are done, return our assembled value
'Sub TESTstrCode()
'MsgBox strCode("^216", "^")
'MsgBox strCode("^^", "^")
'MsgBox strCode("abd^^^013def", "^")
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1