|
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 strEncodeAs(strIn As String, strKey As String) As String
' Procedure : strEncodeAs
' Description: This code translates the digit string supplied in strIn to a base form using the supplied key.
' Useful for taking a date/time stamp and squeezing it into a unique file name.
' Copyright: Chris Greaves Inc.
' Inputs: A possibly empty string of characters and a key string.
' Returns: A string of characters, as a coded form of the input.
' Assumes: Nothing
' Side Effects: None.
' Tested: by the calls shown below.
Dim dblAcc As Double
Dim strResult As String
Dim intChar As Long
' First accumulate the data as a long integer
dblAcc = 0
While Len(strIn) > 0
' dblAcc = 10 * dblAcc + Val(Left(strIn, 1))
dblAcc = 10 * dblAcc
dblAcc = dblAcc + Val(Left(strIn, 1))
strIn = Right(strIn, Len(strIn) - 1)
Wend
' Second, rephrase the long integer as a series of characters
While dblAcc > 0
intChar = (dblAcc Mod 36) + 1
dblAcc = Int(dblAcc / 36)
' dblAcc = GetMod(dblAcc, 36)
strResult = strResult & Mid(strKey, intChar, 1)
Wend
strEncodeAs = strResult
'Sub TESTstrEncodeAs()
'MsgBox strEncodeAs("123", "abcdefghijklmnopqrstuvwxyz")
'MsgBox strEncodeAs("1", "abcdefghijklmnopqrstuvwxyz")
'MsgBox strEncodeAs("", "abcdefghijklmnopqrstuvwxyz")
'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 |