Solved

VB.Net is there a function to return the difference between two values?

Posted on 2006-07-20
2
297 Views
Last Modified: 2010-04-23
I need to compare a zero or greater value to a value that may be negative and return the difference between the two values as a positive number  these variables are all stored as data type Double.
 
For example:  

Value 1 = 17
Value 2 = -4

Would like function to return 21.

Thanks,
Jon
0
Comment
Question by:JMO9966
[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 Comments
 
LVL 14

Accepted Solution

by:
ptakja earned 125 total points
ID: 17151469
Sure ;-)

Diff = Math.Abs(Value1-Value2)

All joking aside, the short answer is no.  However, you could easily write your own.

Public Function Diff(ByVal Value1 As Double, ByVal Value2 As Double) As Double
    Return Math.Abs(Value1 - Value2)
End Function
0
 

Author Comment

by:JMO9966
ID: 17151722
I ended up turning the negative number value2 into a positive and adding to value1.

If FutureBalance < OrderPoint And FutureBalance < 0 Then
            FutureSuggOrder = Math.Abs(FutureBalance) + OrderPoint
        ElseIf FutureBalance < OrderPoint And FutureBalance >= 0 Then
            FutureSuggOrder = OrderPoint - FutureBalance
        Else
            FutureSuggOrder = 0
        End If
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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