Return remainder after subtraction

connexion

Registered User.
Local time
Today, 13:18
Joined
Jul 30, 2003
Messages
72
Perhaps my brain is still awash with beer!?

I was sure that there was a simple function (a bit like datediff) that returns the remainder when one number is subtracted from another.

I thought i had this burried in a database somewhere but can't seem to find
it. Can anyone give me a hint as to what it's called please?

Many Thanks

Vince
 
Hi -

Would the eval() function provide what you're after?
From the debug window:

x = 99
y = 34
? cstr(eval(x-y) * 2)
130

Bob
 
There is no built in function to return the remainder of a subtraction, below is a simple function that will give you the remainder.

Public Function MinusRemainderCalculation(FirstNumber As Double, SecondNumber As Double) As Double

On Error Resume Next

MinusRemainderCalculation = (FirstNumber - SecondNumber) - Fix(FirstNumber - SecondNumber)

End Function

Private Sub Form_Load()

Dim dblGetResult As Double

On Error Resume Next

dblGetResult = MinusCalculationRemainder(12.34, 6.22)

MsgBox dblGetResult 'Displays a result of 0.12

End Sub
 
Well, I'm confused. I thought the 'remainder' in subtraction was called the DIFFERENCE, and you get it like this:
7-5=2
7 minus 5 equals 2 (the difference).

I really don't see the correlation between 12.34, 6.22, and 0.12.
 
Well, I'm confused. I thought the 'remainder' in subtraction was called the DIFFERENCE, and you get it like this:
7-5=2
7 minus 5 equals 2 (the difference).


Hi Sergeant

Yes you are correct, but what I have posted is a substitute of the VB MOD function, but instead of it being used by division it used by subtraction. As this is how I understood the original question to be.

Allan
 
I understand the assumption that he is talking about a modulus. That still doesn't explain this:

I really don't see the correlation between 12.34, 6.22, and 0.12.
 
Hi Sergeant

Now you come to mention it neither do I, dont know what I was on when I wrote that one. I had it in my head to give him just the decimal side of the remainder. Sorrow to have caused you so much confusion:) .

Allan
 
I'm getting too old for this, I think I'll go and lie down in a dark room.

Brian
:confused: :confused: :confused:
 
I'm not really a maths person but here goes...

7 divided by 4 = 1.75

the remainder = 0.75

times this by 4 and you get 3.

12 divided by 5 = 2.4

the renainder = 0.4

times this by 5 and you get 2.

See were I'm going with this?

Dim Num1 as integer, Num2 as integer
Dim Whole as integer, Remain as integer

Whole = int(Num1/Num2)
Reamin = Num2 * ((Num1/Num2) - Whole)


Something like that anyway (can't check as Access needs reinstalling on my PC)

Take care.
 
The original post was really vague and the terminology was either incorrect or lacking additional substance.

You don't need a function or anything special for the difference in subtraction, so I'll assume you mean the remainder. You can use Mod (it's the built-in version of what David.Brent was expessing):

Code:
Remainder = num1 Mod num2

From the help file:
The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result
 
Last edited:

Users who are viewing this thread

Back
Top Bottom