faqts : Computers : Programming : Languages : Asp : ASP/VBScript : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 9 people (56%) answered Yes
Recently 4 of 8 people (50%) answered Yes

Entry

Can I turn one number into single digits by separating each digit in the number into it's own variable?

May 19th, 2000 06:44
unknown unknown, Bruce Anwyl


e.g.. var=12345
var1=1
var2=2
var3=3
var4=4
var5=5

Solution:

The following VB code produces
6
5
4
3
2

    Dim num As Integer
    Dim i As Integer
    Dim digit As Integer

    num = 23456
    Do While num > 0
        digit = num Mod 10
        Print digit
        num = num \ 10
    Loop

Things to note are:

1) The \ operator does integer division and if you use / instead the 
example does not work.
2) The Mod operator gives the remainder after integer division.



© 1999-2004 Synop Pty Ltd