Solved

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

Posted on 2006-07-20
288 Views
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
Question by:JMO9966

LVL 14

Accepted Solution

ptakja earned 125 total points
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

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …