Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

curWeeklyPay1 = 0

Posted on 2004-04-07
3
Medium Priority
?
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
jmwheeler earned 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

636 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