Solved

curWeeklyPay1 = 0

Posted on 2004-04-07
3
156 Views
Last Modified: 2010-05-02
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
Comment
Question by:gonzal13
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
jmwheeler earned 50 total points
ID: 10776947
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
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10776974
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
 
LVL 13

Author Comment

by:gonzal13
ID: 10810356
Thanks, you are right. I was having tunnel vision and was hyperfocused. The points are yours
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question