- Local time
- Today, 04:50
- Joined
- Jul 9, 2003
- Messages
- 16,285
Re: Who's bored?
i'm not that bored!!!!
i'm not that bored!!!!
Private Function DecimalToBase(ByVal dec As Double, ByVal base As Integer, ByVal fill_digits As Integer, ByVal Alpha As Boolean) As String
Dim decimalNumber, i, j As Integer: i = 0
Dim baseNumber(100) As String
If dec = 0 Then
baseNumber(j) = 0
i = i + 1
End If
While dec > 0
baseNumber(i) = dec Mod base
dec = IIf(dec >= base, CDbl(Split(CStr(dec / base), ".")(0)), 0)
i = i + 1
Wend
i = i - 1
If Alpha Then
For j = i To 0 Step -1
DecimalToBase = DecimalToBase & Chr(CInt(65 + baseNumber(j)))
Next
For i = 0 To fill_digits - Len(DecimalToBase)
DecimalToBase = "A" & DecimalToBase
Next
Else
For j = i To 0 Step -1
DecimalToBase = DecimalToBase & baseNumber(j)
Next
For i = 0 To fill_digits - Len(DecimalToBase)
DecimalToBase = "0" & DecimalToBase
Next
End If
End Function
Private Function DecimalToBase(ByVal dec As Double, ByVal base As Integer, ByVal fill_digits As Integer, ByVal Alpha As Boolean) As String
Dim decimalNumber, i, j As Integer: i = 0
Dim baseNumber(100) As String
If dec = 0 Then
baseNumber(j) = 0
i = i + 1
End If
While dec > 0
baseNumber(i) = dec Mod base
dec = IIf(dec >= base, CDbl(Split(CStr(dec / base), ".")(0)), 0)
i = i + 1
Wend
i = i - 1
If Alpha Then
For j = i To 0 Step -1
DecimalToBase = DecimalToBase & IIf(base > 10 And base <> 26, " ", vbNullString) & Chr(CInt(65 + baseNumber(j)))
Next
For i = 0 To fill_digits - Len(DecimalToBase)
DecimalToBase = "A" & IIf(base > 10 And base <> 26, " ", vbNullString) & DecimalToBase
Next
Else
For j = i To 0 Step -1
DecimalToBase = DecimalToBase & IIf(base > 10 And base <> 26, " ", vbNullString) & baseNumber(j)
Next
For i = 0 To fill_digits - Len(DecimalToBase)
DecimalToBase = "0" & IIf(base > 10 And base <> 26, " ", vbNullString) & DecimalToBase
Next
End If
End Function
<-- ??so if i want the chr sequence for 99999 what do i enter into the parameters?
MsgBox DecimalToBase(99999, 26, 0, True)
Public Function GetSequence(ByVal lngNumber As Long) As String
Dim lngTemp As Long
Dim strChar As String
Const BASE As Long = 26
lngTemp = lngNumber \ BASE
strChar = Chr(lngNumber - (lngTemp * BASE) + 65)
If lngTemp = 0 Then
GetSequence = strChar
Else
GetSequence = GetSequence(lngTemp - 1) & strChar
End If
End Function
Public Function GetStringSeq(ByVal InputVal As Long) As String
If InputVal < 1 Then Exit Function
Dim modVal As Long: Const ASC_@ = 64
If InputVal <= 26 Then
GetStringSeq = Chr(InputVal + ASC_@)
Else
modVal = InputVal Mod 26
GetStringSeq = GetStringSeq((InputVal \ 26) - Abs(modVal = 0)) & _
Chr(modVal + ASC_@ + IIf(modVal = 0, 26, 0))
End If
End Function