• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 712
  • Last Modified:

fMod in VB

Is there any PREMADE function of fMod in VB ?

I need to phrase some numbers and would like to use a internal function for this... the current way just "feels wrong"


9.87 fmod 1 = 0.87
9.87 fmod 2 = 1.87

Yes.. i can code something like that myself ... but for i am looking for an INTERNAL function that does this... something that would also please me would be Fx(9.87) = 0.87

The "normal" mod and \ only return integers but i also need to "keep" the real part of my numbers...

1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
no, VB doesn't have that.

9.87 fmod 1 ---> 9.87 - cint(9.87)

Thus, the function would be

Public Function fmod( v as double , m as long) as double
   fmod = cint(v) - 1 + m
End Function
Mayank SAssociate Director - Product EngineeringCommented:
rdrunnerAuthor Commented:
Thanks for both tries ;)

- Angelll thats (kinda) how i currently do it myself ;)
I said i dont want to write a function but i am looking for the internal ones that acomplish those functions...

And your function should be something like :

Public Function fMod(nNumber As Double, nDiv As Double) As Double
Dim nTmp As Double
nTmp = nNumber / nDiv
nTmp = (nTmp - CInt(nTmp))
If nTmp < 1 Then nTmp = nTmp + 1
fMod = nTmp * nDiv
End Function

- Mayankaeagle : Thats VB.NET - I was looking for vb6

Angel correctly answered your question in that case.  The answer is no. ;)
rdrunnerAuthor Commented:
Ok then ;)

My "math english" isnt the best so i thought i just was unable to translate it correctly ;)

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now