'Function mymod(n As Double,m As Integer) As Double

' Return Fix(n) Mod m + n - Fix(n)

'End Function

Code: Select all

`Declare Function mymod(n As Double,m As Integer) As Double`

Dim As Double n

Dim As Integer m

n=54.321

m=10

Print mymod(n,m)

Sleep

End

'i wish this would work

'Function mymod(n As Double,m As Integer) As Double

' Return Fix(n) Mod m + n - Fix(n)

'End Function

'my really bad solution

Function mymod(n As Double,m As Integer) As Double

Select Case n

Case 0

mymod = 0

Case CDbl(m)

mymod = CDbl(m)

Case Else

If InStr(Str(n),"e")<>0 Then

mymod=0

Else

If InStr(Str(n),".")<>0 Then

mymod=Val(Str(val(Mid(Str(n),1,InStr(Str(n),".")-1)) Mod m)+"."+Mid(Str(n),InStr(Str(n),".")+1))

Else

mymod = (n Mod m)

EndIf

End If

End Select

End Function