Variant Data Type variables -Can't print individually

Quote:

> Hi, I've got this big problem and I really need help.

> I'm writing a program that attempts to print the a variant variable value

> individually. Variable num must be of type Variant and always holds a 9

> digit number.

> For example num = 123456789 as variant

> I need to disply it like this :

> 1

> 2

> 3

> 4

> 5...

> Option Explicit

> Dim num As Variant

> Private Sub frmPrint_Click()

> Dim obj As Variant

> Dim lenNum As Integer

> Dim i As Integer

> Dim strNumArr(1 To 9) As Variant

> num = 123456789

> For i = 1 To 9 ' An attempt to place the first number in variable num

> as the first element of array strNumarr

> strNumArr(i) = num(1) ' this doesn't work

> Next i

> For Each obj In strNumArr

> Picture1.Print obj

> Next

> End Sub

> Thanks for your help.

> md.

Hi.

1. Trivial method: convert your number to a string (CSTR) then print

each character at a time (MID).

2. If you meant that no conversion to a string must be done, then

extract your digits using integer and modulo division of your number by

the powers of 10. Since 9 digits are required, use Long type to hold

your intermediate calculations. Now, each digit is the weight of 10 to

the power of the digit's position (10^dp) - starting from position zero

for LSD up to eight for MSD. Start counting from 8 to 0, for each step

divide the "current number" by 10^counter and take the integer of this

division (the quotient). This is the required digit at place "count".

Next, have the remainder (using MOD) of the division, decrease your

counter and repeat this process:

lngCurrentNum = num

For Counter = 8 to 0 step -1

lngPower = 10 ^ Counter

strNumArr(Counter+1) = Int(lngCurrentNum / lngPower) ' Quotient

lngRemainder = num Mod lngPower ' Remainder

lngCurrentNum = lngRemainder ' Update "current number"

Next Counter

Now you should have your digits in strNumArr (BTW, str prefix is used

for strings, better change to something else).

HTH,

Yaniv.