#VBA, 157 103 bytes
VBA, 157 103 bytes
The Variant / Decimal data type in VBA only allows up to 29 digits of precision. 2^128 is 39 digits long so we have to smoosh two variables together. Variant is the default for any undeclared variable so that's easy. Every time the right-hand side (a
) rolls over, set it back to 0 and iterate the left-hand side (b
) by 1. To handle leading zeros, we set the format to be 28 digits long the first time that a
rolls over. This has a smaller max than the string method but it's well above 2^128.
Sub c()
Do
a=a+1
If a=10^28Then b=b+1:a=0:f=Replace(Space(28)," ",0)
Debug.?b &Format(a,f)
Loop
End Sub
Once it's formatted for humans, it looks like this:
Sub c()
Do
a = a + 1
If a = 10 ^ 28 Then b = b + 1: a = 0: f = Replace(Space(28), " ", 0)
Debug.Print b & Format(a, f)
Loop
End Sub
Previous method using strings:
It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.
Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub