• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

curWeeklyPay1 = 0

I have the following simple question. I am studying visual basic and spent several hours trying to figure out why an equation turns out to be zero

Dim curWeeklyPay1 As Currency
curWeeklyPay1 = 250 + (2000 - 250) * 0.15 - 1000
curweeklypay1 through the debug shows a value of zero.

gonzal13(Joe)
0
gonzal13
Asked:
gonzal13
  • 2
1 Solution
 
jmwheelerCommented:
I tried it and did not get 0, I got -487.5 which is the correct answer.  Try putting   Option Explicit  at the top of your code like the example below, if you get an error message about Variable not defined then you misspelled your variable somewhere.  This sounds like a very likely cause of the problem.  I would suggest always using Option Explicit, it forces you to declare you variables and will save you a lot of headaches when creating large programs.

Option Explicit

Private Sub Command1_Click()

    Dim curWeeklyPay1 As Currency
    curWeeklyPay1 = 250 + (2000 - 250) * 0.15 - 1000
    MsgBox (curWeeklyPay1)
   
End Sub
0
 
jmwheelerCommented:
Also, one more thought when using debug.  There are some other possibilities.  CurWeeklyPay1 will show 0 until this (curWeeklyPay1 = 250 + (2000 - 250) * 0.15 - 1000) line of code is run, so if you break on this line you will see 0.  Also, you are using Dim curWeeklyPay1 which will cause it to lose it's value after you leave it's current scope.  For example in my code from my previous post, curWeeklyPay1 would not retain a value after the Command1_Click() subroutine is finished.  You could try changing your declarion to :

Private CurWeeklyPay1 as Currency

and see if that helps.
0
 
gonzal13RetiredAuthor Commented:
Thanks, you are right. I was having tunnel vision and was hyperfocused. The points are yours
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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