CiCi Miniseries #1
Inside Front Cover Source Code
I've included three functions below. The first one dumps it's output to a field which is "theText" translated into 5 different bases. The first is base 2 which everybody knows is binary. The third, base 8, is octal. The fourth, base 16, is hexadecimal (which is what I used).
The second function actually does the base translation of the text parameter. The third function converts a numeric value to a number or letter. And the last function provides integer division, because, as we all know, Visual Basic ROUNDS like there's no tomorrow.
In order for this code to be functional, you will need to create a form with a multi-line field and a command button. They should be named: cTextFld and Command2 respectively. It should come right up. Then you can see what the hell base 32 is?
'Copyright 1999 Spilled
Milk, all rights reserved
Option Compare Database
Option Explicit
Private Sub Command2_Click()
Dim pos As Long
Dim theText As String
cTextFld = ""
theText = "Parker Smart"
pos = 1
Do While (pos <= Len(theText))
cTextFld =
cTextFld & " " & ConvertDecToBase(Asc(Mid(theText, pos, 1)), 2, 8)
pos = pos + 1
Loop
cTextFld = cTextFld & vbCrLf & vbCrLf
pos = 1
Do While (pos <= Len(theText))
cTextFld =
cTextFld & " " & ConvertDecToBase(Asc(Mid(theText, pos, 1)), 4, 4)
pos = pos + 1
Loop
cTextFld = cTextFld & vbCrLf & vbCrLf
pos = 1
Do While (pos <= Len(theText))
cTextFld =
cTextFld & " " & ConvertDecToBase(Asc(Mid(theText, pos, 1)), 8, 3)
pos = pos + 1
Loop
cTextFld = cTextFld & vbCrLf & vbCrLf
pos = 1
Do While (pos <= Len(theText))
cTextFld =
cTextFld & " " & ConvertDecToBase(Asc(Mid(theText, pos, 1)), 16, 2)
pos = pos + 1
Loop
cTextFld = cTextFld & vbCrLf & vbCrLf
pos = 1
Do While (pos <= Len(theText))
cTextFld =
cTextFld & " " & ConvertDecToBase(Asc(Mid(theText, pos, 1)), 32, 2)
pos = pos + 1
Loop
End Sub
Private Function ConvertDecToBase(ByVal pValue
As Long, ByVal pBase
As Long, ByVal pPadding
As Long) As String
Dim theRoot As Long
Dim theText As String
theRoot = pValue
Do While (theRoot > 0)
theText =
DigitToHex(theRoot Mod pBase) & theText
theRoot =
IntDiv(theRoot, pBase)
Loop
If (Len(theText) < pPadding) Then
pPadding =
pPadding - Len(theText)
Do While (pPadding > 0)
theText = "0" & theText
pPadding = pPadding - 1
Loop
End If
ConvertDecToBase = theText
End Function
Private Function DigitToHex(ByVal pValue
As Long) As String
If (pValue >= 0 And pValue <= 9)
Then
DigitToHex = CStr(pValue)
Else
DigitToHex = Chr(Asc("A") + (pValue - 10))
End If
End Function
Private Function IntDiv(ByVal pValue As
Long, ByVal pDivisor As
Long) As Long
If (pDivisor <> 0) Then
IntDiv =
(pValue - (pValue Mod pDivisor)) / pDivisor
End If
End Function