| re: Creating a unique number from a text string
In VBA numbers are limited in size by the number of bytes used to store
them in memory. Unless on messes with variant decimals, 8 bytes seems
to be the maximum.
So it will be hard to represent a string of 47 bytes with a number
which can deal with only 8.
If you would like a number based on the first 8 bytes of the string, or
you would like to require an 8 character password/login then this
function (cobbled together over coffee and subject therefore to the
appelation, "Air Code") might help. I have used currency because it is
stored as 8 bytes and because it is simple, usually being displayed in
#.# and not scientific notation.
Option Explicit
Private Declare Sub CopyMemory _
Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
Function CurrencyFromString(ByVal s As String) As Currency
s = s & String(8, vbNullChar)
s = Left(s, 8)
Dim a() As Byte
a = StrConv(s, vbFromUnicode)
CopyMemory CurrencyFromString, a(0), 8
End Function
Sub text()
Debug.Print CurrencyFromString("Dixie")
End Sub |