Solved

# fMod in VB

Posted on 2003-03-21
Medium Priority
635 Views
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"

example

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...

0
Question by:rdrunner
[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

LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 200 total points
ID: 8180524
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
0

LVL 30

Expert Comment

ID: 8180540
0

LVL 11

Author Comment

ID: 8180730
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

0

LVL 38

Expert Comment

ID: 8180833
0

LVL 11

Author Comment

ID: 8180870
Ok then ;)

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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
###### Suggested Courses
Course of the Month7 days, 23 hours left to enroll