Who's Bored? (2 Viewers)

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 04:50
Joined
Jul 9, 2003
Messages
16,285
Re: Who's bored?

i'm not that bored!!!!
 

BlueIshDan

☠
Local time
Today, 00:50
Joined
May 15, 2014
Messages
1,122
Re: Who's bored?

Here is a Decimal to Base(#) converter :D
Of which may be a bit broken for higher numbers lol.

Code:
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
 
Last edited:

vbaInet

AWF VIP
Local time
Today, 04:50
Joined
Jan 22, 2010
Messages
26,374
Re: Who's bored?

How far can it go?
 

BlueIshDan

☠
Local time
Today, 00:50
Joined
May 15, 2014
Messages
1,122
Re: Who's bored?

well i know for sure that binary(base2), octal (base8) and Hexavigesimal Alphabetical (Base26) work.
 

vbaInet

AWF VIP
Local time
Today, 04:50
Joined
Jan 22, 2010
Messages
26,374
Re: Who's bored?

So if I want the chr sequence for 99999 what do I enter into the parameters?
 

BlueIshDan

☠
Local time
Today, 00:50
Joined
May 15, 2014
Messages
1,122
Re: Who's bored?

Never mind it works for all, I had to put a space between the numbers coming out because it became confusing as to which digit was being counted lol.

This will make the output a little less confusing.

Code:
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
 

BlueIshDan

&#9760;
Local time
Today, 00:50
Joined
May 15, 2014
Messages
1,122
Re: Who's bored?

What do you mean for chr sequence? The 26 based Aplha results?
If so

Code:
            MsgBox DecimalToBase(99999, 26, 0, True)

Haha it comes out as FRYD
 

vbaInet

AWF VIP
Local time
Today, 04:50
Joined
Jan 22, 2010
Messages
26,374
Re: Who's bored?

Just going by the OP. I'm not sure why you added the extra bits, you obviously got too excited :D

Base and alpha for 256.
 

BlueIshDan

&#9760;
Local time
Today, 00:50
Joined
May 15, 2014
Messages
1,122
Re: Who's bored?

Value 256 in base(256) = 1 0
255 in base 256 = 255
 

vbaInet

AWF VIP
Local time
Today, 04:50
Joined
Jan 22, 2010
Messages
26,374
Re: Who's bored?

What about the character sequence for 256 as explained in the OP?
 

BlueIshDan

&#9760;
Local time
Today, 00:50
Joined
May 15, 2014
Messages
1,122
Re: Who's bored?

I added the extra bit so that you could modify it the way you like it. For example, binary with no filled digits wouldn't look so binary. Making the value seem to fit into 8 places makes it look more binary.

so isntead of 101 for 5 it will come out as 00000101
 

BlueIshDan

&#9760;
Local time
Today, 00:50
Joined
May 15, 2014
Messages
1,122
Re: Who's bored?

Character sequence only make sense to use when working in base(26) because it has the same roll over.

If you wish to use Alpha with different bases you're going to get characters(65) and up to an error saying no characters exist. lol
 

BlueIshDan

&#9760;
Local time
Today, 00:50
Joined
May 15, 2014
Messages
1,122
Re: Who's bored?

I'm off in two minutes and I'm glad to say this thread has made my Friday go by that much quicker! :D
 

vbaInet

AWF VIP
Local time
Today, 04:50
Joined
Jan 22, 2010
Messages
26,374
Re: Who's bored?

Just before you go, you haven't told me what the character sequence for 256 is? I'm about to show you something.
 

BigHappyDaddy

Coding Monkey Wanna-Be
Local time
Yesterday, 20:50
Joined
Aug 22, 2012
Messages
205
Re: Who's bored?

Ok, my version:
Code:
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

A recursive function that determines the Alpha value, going from the least significant digit upwards (right to left).

Thoughts, questions, concerns?
 

vbaInet

AWF VIP
Local time
Today, 04:50
Joined
Jan 22, 2010
Messages
26,374
Re: Who's bored?

Finally someone with a recursive code!!!

Here's a quick one of mine. Perhaps it can be written shorter:
Code:
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
Not tested fully but seems to do the job.

BigHappyDaddy and BlueIshDan, the character sequence for 256 is IV (the last column in an Excel spreadsheet). Maybe tweak your codes. BigHappy seems closer to the solution.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 04:50
Joined
Sep 12, 2006
Messages
15,662
Re: Who's bored?

not looked in detail, but its going to be something simple using mod 26
 

Users who are viewing this thread

Top Bottom