As noted, the easiest way to do this is by converting the number into a string and then parsing out the individual digits according to their position in the string....
[tt]
MyNumber& = 1234
MyStringNum$ = LTrim(Str$(MyNumber&))
Digits = Len(MyStringNum$)
[/tt]
' Make sure the number is less than 5 digits.
' This will trunctate the rightmost digits
' after the fourth digit.[tt]
If Digits > 4 Then
MyStringNum$ = Left$(MyStringNum$, 4)
End If
[/tt]
' Make sure the number is at least 4 digits.
' Using a number with less than 4 digits will
' return zeros until the actual digits are encountered:
' 123 will return 0 1 2 3
' 12 will return 0 0 1 2... and so on.[tt]
MyStringNum$ = Right$("0000" + MyStringNum$, 4)
[/tt]
' Get the individual digits.[tt]
FirstNum& = Val(Mid$(MyStringNum$, 1, 1))
SecondNum& = Val(Mid$(MyStringNum$, 2, 1))
ThirdNum& = Val(Mid$(MyStringNum$, 3, 1))
FourthNum& = Val(Mid$(MyStringNum$, 4, 1))
PRINT FirstNum&, SecondNum&, ThirdNum&, FourthNum&
[/tt]
You could always do this the
hard way... That is, by retrieving the individual digits using arithmetic....
' Make sure the number is less than 5 digits.[tt]
If Digits > 4 Then
MyNumber& = MyNumber& \ (10 ^ (Digits - 4))
End If
[/tt]
' Make sure the number is at least 4 digits.
' (multiply by 10000 then extract by getting the
' integer portion after dividing by an appropriate number).[tt]
TmpNumber& = MyNumber& * 10000
FirstNum& = TmpNumber& \ 10000000
Tmp& = FirstNum& * 10000000
SecondNum& = (TmpNumber& - Tmp&) \ 1000000
Tmp& = (FirstNum& * 10 + SecondNum&) * 1000000
ThirdNum& = (TmpNumber& - Tmp&) \ 100000
Tmp& = ((FirstNum& * 100) + (SecondNum& * 10) + ThirdNum&) * 100000
FourthNum& = (TmpNumber& - Tmp&) \ 10000
PRINT FirstNum&, SecondNum&, ThirdNum&, FourthNum& [/tt]