Solved

# specifying decimal places in code

Posted on 2005-04-21
136 Views
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.
0
Question by:gonzal13

LVL 48

Expert Comment

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

LVL 48

Expert Comment

b is still same as 15 either...
0

LVL 65

Expert Comment

>dim A as as currency
You have two 'as' here, should only be one.
0

LVL 65

Expert Comment

I get 37.5 as well.   There is no way you should be getting anything different, if this code block is correct.
0

LVL 13

Author Comment

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

LVL 65

Accepted Solution

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
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

LVL 48

Expert Comment

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

LVL 13

Author Comment

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

LVL 13

Author Comment

Ok, slightly embarasssed, I found the problem in another portion of the code.

Last item is to designate two decimal places.

Joe
0

## Featured Post

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…