Link to home
Start Free TrialLog in
Avatar of gonzal13
gonzal13Flag for United States of America

asked on

specifying decimal places in code

dim A as as currency
dim b as currency
b = 15  'note: this value can change
A= 2.5 * b

This ends in B = 30 which is not correct.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Private Sub Form_Load()
    Dim A As Currency
    Dim b As Currency
    b = 15  'note: this value can change
    A = 2.5 * b
    MsgBox A
End Sub

i got 37.5 not 30....
b is still same as 15 either...
>dim A as as currency
You have two 'as' here, should only be one.
I get 37.5 as well.   There is no way you should be getting anything different, if this code block is correct.
Avatar of gonzal13

ASKER

dim A as as currency
dim b as currency
b = 15  'note: this value can change
A= 2.5 * b

This ends in A = 30 which is not correct.

Here is the exact code.
Dim BETBJ As Currency
Betone = 15

If NETLow10 <= NetRnge1 And (E = 1 And F = 10) Or (E = 10 And F = 1) _
            Then BETBJ = 2.5 * BETONE

Betbj = 30 !

ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
check the value of BETONE

you can add debug.print to debug the variables value, like:



Dim BETBJ As Currency
Betone = 15

If NETLow10 <= NetRnge1 And (E = 1 And F = 10) Or (E = 10 And F = 1) Then

  debug.print "BETONE = " & BETONE

   BETBJ = 2.5 * BETONE

  debug.print "BETBJ = " & BETBJ

end if


just guess that BETONE equals to 12 (which is 30 / 2.5) ...
I guess the scope has changed.

I have tried various senarios listed below and they do not make any sence.

CONST BJ AS CURRENCY =2
BETTHREE IS A VARIABLE AND IN THIS CASE 15
Using debug:

Bet1 = 2.5  * BETTHREE  
Bet1 = 30 and BETTHREE = 15

Bet1 = 2  * BETTHREE  
Bet1 = 30 and BETTHREE = 15

Now see THIS!
Bet1 = 1 * BETTHREE  
Bet1 = 30 and BETTHREE = 15 No I  am not on methaphedamines!

Bet1 =  BETTHREE  
Bet1 = 30 and BETTHREE = 15

Bet1 = 3 *  BETTHREE  
If NETLow10 > NetRnge2 And (E = 1 And V(5) = 10) Or (E = 1 And V(5) = 1) Then _
Bet1 = 30 and BETTHREE = 15

Bet1 = BETTHREE + BETTHREE + 7.5 Where betthree = 15  Bet1 = 30



Sometimes when I run a module I will get the following comment  “ Compile error: End IF without block IF. I do not have an End IF senario.

I would have to rewrite the multitude of if statements with IF … Then  End IF but the ElseIF does not fit.

The module consists of many IF statements
Ok, slightly embarasssed, I found the problem in another portion of the code.

Last item is to designate two decimal places.

Joe