Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Wierd one. Subtraction does not work.


Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-2012, 02:50 PM
DrDsNo1 DrDsNo1 is offline
Newcomer
 
Join Date: Nov 2010
Posts: 3
Question Wierd one. Subtraction does not work.


A) varBaseDiscount = (varBase * varDiscountRate)
varBaseDiscount=5.5D VarBase=55D VarDiscountRate=.1D

B) varBaseDiscounted = varBase - varBaseDiscount
varBaseDiscounted=0D varBase=55D varBaseDiscount=5.5D


c) varDolliesDiscounted = varDollies - varBaseDiscount
varDolliesDiscounted=74.5D varDollies=80D varBaseDiscount=5.5D

Three consecutive lines in program are equations A B C. All values are Decimal.
Equations A & C work. B does not.
Can anyone explain why not?
Reply With Quote
  #2  
Old 04-24-2012, 03:52 PM
Gruff's Avatar
Gruff Gruff is offline
Bald Mountain Survivor

Super Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA
Posts: 6,297
Default

Since you are only showing pseudo-code we cannot really debug it for you.
Post your actual code.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 04-24-2012, 04:30 PM
snarfblam's Avatar
snarfblam snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 892
Default

Here is a console program:
Code:
Module Module1

    Sub Main()
        Dim varBaseDiscount As Decimal
        Dim varBase As Decimal
        Dim varDiscountRate As Decimal
        Dim varBaseDiscounted As Decimal
        Dim varDollies As Decimal
        Dim varDolliesDiscounted As Decimal

        varBase = 55D
        varDiscountRate = 0.1D
        varBaseDiscount = varBase * varDiscountRate
        Console.WriteLine("varBaseDiscount = {0}", varBaseDiscount)

        varBase = 55D
        varBaseDiscount = 5.5D
        varBaseDiscounted = varBase - varBaseDiscount
        Console.WriteLine("varBaseDiscounted = {0}", varBaseDiscounted)

        varDollies = 80D
        varBaseDiscount = 5.5D
        varDolliesDiscounted = varDollies - varBaseDiscount
        Console.WriteLine("varDolliesDiscounted = {0}", varDolliesDiscounted)

        Console.ReadLine()
    End Sub

End Module
Here is the output:
Code:
varBaseDiscount = 5.5
varBaseDiscounted = 49.5
varDolliesDiscounted = 74.5
This is called a sanity check. A little program to demonstrate that the computer can indeed subtract properly. Once this is confirmed, you need to find the important difference between your program and the sanity check that is causing them to behave differently.

Do you have Option Explicit On and Option Strict On?
__________________
C# _VB.NET _
Reply With Quote
  #4  
Old 04-24-2012, 05:15 PM
DrDsNo1 DrDsNo1 is offline
Newcomer
 
Join Date: Nov 2010
Posts: 3
Default

sanity check works. option explicit and strict are on.
Reply With Quote
  #5  
Old 04-24-2012, 08:04 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,505
Default

If you don't post your code, time is wasted.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply

Tags
subtract


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->