[simpits-tech] Changing numbers in VB6.0

simpits-tech@simpits.org simpits-tech@simpits.org
Mon, 17 Feb 2003 14:46:58 -0600


Ken Trager wrote:
> 
> Hello all
> 
> Here is the problem
> 
> A/P VSI is displayed in four numbers   - - - like 1200
> 
> question is how to break that number down into single digits
> 
> Iam trying to sent out the data to display it but I need to send it out
> one digit at a time.
> 
> This example when be
> 
> First number - 1
> Second - 2
> Third - 0
> Fourth - 0
> 
> Is there a way to do this in VB programing?

Yup, a few ways. I had to do it once for a class assignment, but it's
been a few years. Let's see, I think I did it with a function that used
a bunch of if/then statements then division and subtraction. Basically
if the number is greater than 1000 then divide by 1000 and ignore the
decimals to get the first number, then subtract 1000 and divide by 100
to get the second, subtract that number and divide by 10 to get the
third, etc. Like this:

Original number = x
First digit = a
Second = b
Third = c
Fourth = d

x = 1234
a = x/1000 = 1
b = (x-(1000a))/100 = 2
c = (x-(1000a)-(100b))/10 = 3
d = (x-(1000a)-(100b)-(10c)) = 4

You just have to dimension the variables as... which is it that has no
decimals? I've gotten pretty rusty with VB.

It can also be done by turning it into a string and parsing it, but I
was never much good at parsing strings.
-- 
Steve
mysticz28@swbell.net
Jesus saves, Budda enlightens, Cthulhu thinks you'll make a nice
sandwich.