Solved

curWeeklyPay1 = 0

Posted on 2004-04-07
3
153 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now