|
-
Aug 12th, 2008, 08:51 AM
#1
Thread Starter
Addicted Member
[RESOLVED] [2005] Get value range of variable
Hi all,
I am having a problem. I need to know how to check if a value is equal to plus or minus five million of another value.
For instance
Code:
if amount 1 = amount2 +- 5000000 then
I know this is not correct, because it assumes you want to subtract 5milli from amount2. I don't actually want to subtract anything from amount2, just see if amount1 falls within that range. For example, if amount1 is 10milli, and amount2 is 13milli, then that is considered a "match" (for the purposes of this question anyway).
I know there's probably something (again) fundamental that I'm missing.
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
Aug 12th, 2008, 09:28 AM
#2
Re: [2005] Get value range of variable
vb Code:
if amount2 > amount1 and amount2 - amount1 <= 5000000 or amount1 > amount2 and amount1 - amount2 <= 5000000 then
' amount1 is equal to plus or minus five million of amount2
end if
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 12th, 2008, 09:31 AM
#3
Re: [2005] Get value range of variable
Code:
if Amount1 >= (amount2 - 5000000 ) orelse Amount1 <= (amount2 + 5000000 ) then
'Match
end if
eidt: Paul's logic is much better
__________________
Rate the posts that helped you 
-
Aug 12th, 2008, 09:43 AM
#4
New Member
Re: [2005] Get value range of variable
Or if you dont want to type that long line of code over and over again, you can put it in a little function that returns true or false:
Code:
Public Function PlusMinus(ByVal origValue As Integer, ByVal compareValue As Integer)
Dim maxDifference As Integer = 5000000 'In this case, it is 5 million
If compareValue > origValue And compareValue - origValue <= maxDifference _
Or origValue > compareValue And origValue - compareValue <= maxDifference Then
Return True
Else
Return False
End If
End Function
-
Aug 12th, 2008, 10:36 AM
#5
Re: [2005] Get value range of variable
Code:
Dim num1 As Long = 13000000
Dim num2 As Long = 18000000
Dim num3 As Long = Math.Abs(num1 - num2)
Const variance As Long = 5000000
Debug.WriteLine(num3.ToString)
If num3 <= variance Then
Debug.WriteLine("in range")
Else
Debug.WriteLine("outside range")
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|