[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

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.
0
gonzal13
Asked:
gonzal13
  • 3
  • 3
  • 3
1 Solution
 
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
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>dim A as as currency
You have two 'as' here, should only be one.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
Jim HornMicrosoft 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:
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now