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.
LVL 13
gonzal13RetiredAsked:
Who is Participating?
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
Execute the below code.  When code stops at the STOP line, step through code by hitting your {f8} key, and see which line executes...
_____________
Dim BETBJ As Currency
STOP                '<---- Added
Betone = 15

If NETLow10 <= NetRnge1 And (E = 1 And F = 10) Or (E = 10 And F = 1) Then
      BETBJ = 2.5 * BETONE
Else
      Msgbox "Your above calculation did not calculate"
End If

msgbox BETBJ
0
 
Ryan ChongCommented:
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....
0
 
Ryan ChongCommented:
b is still same as 15 either...
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>dim A as as currency
You have two 'as' here, should only be one.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
I get 37.5 as well.   There is no way you should be getting anything different, if this code block is correct.
0
 
gonzal13RetiredAuthor Commented:
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 !

0
 
Ryan ChongCommented:
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) ...
0
 
gonzal13RetiredAuthor Commented:
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
0
 
gonzal13RetiredAuthor Commented:
Ok, slightly embarasssed, I found the problem in another portion of the code.

Last item is to designate two decimal places.

Joe
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.