questions

I

icestationzbra

dave,

thanks for the explanation.

i just have a couple of more questions about what you mentioned.

in effect, until i have a number that is 4 digits or longer, there wil
always be a null padding around the number if i use long. is tha
correct? in which case, can i presume that if the number is less than
digits long when the variable is declared as 'long', i will always hav
to use trim? or is there a way to circumvent it, that is, carry o
without having to using trim and cstr (i had also tried cstr whil
experimenting)?

thanks,

mac
 
D

Dave Peterson

It's not really padded with spaces--since you could only go from 1 to 9999. And
Longs can be anywhere from -2,147,483,648 to 2,147,483,647 (from VBA's help).

It uses 32 bits to represent the numbers.

Kind of like in binary representation:

01010101
(reading right to left) represents
1 one
0 two's
1 four
0 8's
1 16's
0 32's
1 64's
0 128's
or
64+16+4+1
=
85.

Imagine 4 groups of these (32 bits instead of just the 8 I used).

One of the bytes will be use to indicate positive/negative, so there'd be 31
bits available and that would be one honking big number.

2^32 = 4294967296
and if you take the biggest long (2,147,483,647) and subtract the smallest long
(-2,147,483,648), you get
4294967295
(leaving that one bit used as the positive/negative indicator.)

=====

You could also inspect each digit by dividing by powers of 10--but the cstr()
seems easier to me in this case.

Option Explicit
Sub testm()

Dim i As Long
Dim myNum As Long
Dim myTemp As Long

myNum = 1234

For i = 1 To 4
myTemp = ((myNum / 10) - Int(myNum / 10)) * 10
myNum = (myNum - myTemp) / 10
'do something with mytemp
MsgBox myTemp
Next i

End Sub
 
Top