Another VB4.0 Question... 
Author Message
 Another VB4.0 Question...

Is there a bug in VB4.0 when trying to divide?  The following is part of my
code:

    Label51.Caption=a$
    Label53.Caption = b$
    Label55.Caption = (b$ / a$) / 0.01

Basically, a$ is the total amount possible and b$ is the total achieved.
Say that a$=55  and b$=31 : (b$/a$)=.5636363636364; take that and divide by
01 and it should equal 56.36...%

When the code is executed though, the result that is placed into
Label55.Caption is something like 1453256

Any ideas about this?  Please help.



Mon, 22 Mar 1999 03:00:00 GMT  
 Another VB4.0 Question...

Quote:

> Is there a bug in VB4.0 when trying to divide?  The following is part of my
> code:
>     Label51.Caption=a$
>     Label53.Caption = b$
>     Label55.Caption = (b$ / a$) / 0.01
> Basically, a$ is the total amount possible and b$ is the total achieved.
> Say that a$=55  and b$=31 : (b$/a$)=.5636363636364; take that and divide by
> 01 and it should equal 56.36...%
> When the code is executed though, the result that is placed into
> Label55.Caption is something like 1453256
> Any ideas about this?  Please help.

When I first saw this, I boggled, mindwise. I am prompted to ask -
how are your a$ and b$ variables declared? Because the first two
lines treat them as strings (as the $ suffix suggests). Then the
third line appears to be attempting 'string division' which struck
me as rather an odd idea. I've heard of polymorphism and overloading,
but this is ridiculous.

However. Just to be on the safe side, I tried it out. And it does
indeed work. The thing is, I mean it *really* works. My caption
comes out as 56.3636363636364, so, being unable to reproduce your
symptoms, I have nothing further to offer. Peculiar, innit?

--
-------------------------------------------------------------------

BB 74 A4 EF 03 F8 44 C1 F3 75 FE C6 7E F9 6E 43         --- at home
-------------------------------------------------------------------



Mon, 22 Mar 1999 03:00:00 GMT  
 Another VB4.0 Question...


Quote:
>Is there a bug in VB4.0 when trying to divide?  The following is part of my
>code:

>    Label51.Caption=a$
>    Label53.Caption = b$
>    Label55.Caption = (b$ / a$) / 0.01

>Basically, a$ is the total amount possible and b$ is the total achieved.
>Say that a$=55  and b$=31 : (b$/a$)=.5636363636364; take that and divide by
>01 and it should equal 56.36...%

>When the code is executed though, the result that is placed into
>Label55.Caption is something like 1453256

>Any ideas about this?  Please help.

I don't know what VB is doing with this, but if you had showed me this without
the results I would have guesed that it would cause a compile error.  I'm not
really comfortable with implicit conversions of strings to numbers inside
equations.

You might try something like:

    Label51.Caption=a!
    Label53.Caption = b!
    Label55.Caption = (b! / a!) / 0.01

The caption control transparently handles conversion from single to string for
the caption.

Bill Brown



Mon, 22 Mar 1999 03:00:00 GMT  
 Another VB4.0 Question...

The problem is you are dividing a string by a string which works fine, but
then you are dividing by a number. Try this code:
        Label51.Caption= Val(a$)
        Label53.Caption = Val(b$)
        Label55.Caption = Val(b$)) / Val(a$)) / 0.01



Quote:
> Is there a bug in VB4.0 when trying to divide?  The following is part of
my
> code:

>     Label51.Caption=a$
>     Label53.Caption = b$
>     Label55.Caption = (b$ / a$) / 0.01

> Basically, a$ is the total amount possible and b$ is the total achieved.
> Say that a$=55  and b$=31 : (b$/a$)=.5636363636364; take that and divide
by
> 01 and it should equal 56.36...%

> When the code is executed though, the result that is placed into
> Label55.Caption is something like 1453256

> Any ideas about this?  Please help.



Tue, 23 Mar 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VB4 DLLs Question

2. VB4.0 questions help?

3. VB4 newbie questions

4. VB4 simple questions

5. VB4 ComboBox question

6. VB4 + Network question

7. Help: VB4 Commondialog Question

8. VB4 General Questions

9. VB4 RTB question for experts

10. VB4 ListView-Question

11. VB4 Newbie Question

12. VB4 Editor question

 

 
Powered by phpBB® Forum Software