I think I posted this on the old board.

It's a little function I use to generate unique strings.

Typical use: I am tokenising tables - taking each table of a document, cut-and-paste it into a new document and save that new document with a unique file name and replace the cut text with the tokenised name.

I did this back in WordBasic. It makes more sense than {Includetext} when cleaning documents, because it REALLY gets table text out of the way and lets you focus on non-table text.

<pre>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
dblAcc = dblAcc + Val(Left(strIN, 1))
strIN = Right(strIN, Len(strIN) - 1)
' Second, rephrase the long integer as a series of characters
While dblAcc > 0
intChar = (dblAcc Mod 36) + 1
dblAcc = Int(dblAcc / 36)
strResult = strResult & Mid(strKey, intChar, 1)
strEncodeAs = strResult
'Sub TESTstrEncodeAs()
'MsgBox strEncodeAs(Timer, "abcdefghijklmnopqrstuvwxyz")
'MsgBox strEncodeAs(Timer, "0123456789")
'End Sub
End Function