I've been trying to create something similar to a DEC_MAX
constant in vba.
Issue is, it is a bit tricky, because there is no Decimal
data-type!
The closest you can get to a functioning decimal is the CDec()
function which is defined:
Return the Decimal data value that is the result of Expression being Let-coerced to Decimal
So naturally, I thought that any potentially overfowing value would be co-erced to the maximum achievable Decimal
. I tried inserting the max Decimal vb.net value from MSDN Documentation
This is however note true, as attempting to do so will result in an Overflow:
So how would one go about calculating the closest possible approximation of Decimal maximum here? I tried this "computer-bricking" ugly loop of a code:
Private Sub brick_my_Excel()
On Error Resume Next
x = 79228162514264337593543950335 'let's let it auto-coerce i guess
Do
Debug.Print(x)
x = x - 1
Loop
End Sub
This however supresses the overflow altogether, printing the x in almost string-like fashion without paying much attention to the calculation.
So,
- How would one go about calculating it?
- What is the largest possible expression we can pass to the
CDec()
function?