Wont Stop

D

DS

I want the message box to pop up if when you divide the number and its less
than .00 but it's not doing this.
I suspect that the number is a decimal .0096 or some like that. But it
should also stop in that case. Any help appreciated.
Thanks
DS

Public Function SC(myNum As Currency, X As Integer)

Dim myNums As String
Dim myNumDivByX As Currency
Dim portion(100) As Currency
Dim i As Currency
Dim leftover As Currency
Dim absleftover As Currency
Dim addon As Currency

myNumDivByX = Round(myNum / X, 2)
'If a number is less than 0.00
If myNumDivByX = 0# Then
MsgBox "STOP"
ElseIf (myNumDivByX * X) = myNum Then
For i = 1 To X
portion(i) = myNumDivByX
myNums = myNums & portion(i) & vbCrLf
Next i
ElseIf (myNumDivByX * X) <> myNum Then
leftover = myNum - (myNumDivByX * X)
absleftover = Abs(leftover)
If leftover < 0 Then
addon = -0.01
Else
addon = 0.01
End If
For i = 1 To X
If i <= absleftover * 100 Then
portion(i) = myNumDivByX + addon
Else
portion(i) = myNumDivByX
End If
myNums = myNums & portion(i) & vbCrLf
Next i
End If
SC = myNums
End Function
 
P

Paolo

HI DS,
actually if you round 0.0096 with two decimals it's correct that it returns
0.01.
If you wanna stop when you have number that starts with 0.00etc. you can try
to do

tmp_num=left(myNum / X, 4)
if tmp_num=0.00 then
stop

HTH Paolo
 
D

DS

Thanks, I tried this but it still doesn't stop.
Dim tmp As Currency
tmp = Left(myNum / X, 4)
If tmp = 0# Then
MsgBox "Stop"
Else
'Run Code
End If

I tried it on .25 / 26
Thanks
DS
 
J

John Spencer

I might try

IF CStr(myNum/X) Like "0.00*" Then
Msgbox "Stop"

Of course, that is not less than zero. It is less than 0.01.

Perhaps what you want is
IF MyNum/X >= 0 and MyNum/x < .01 THEN
MsgBox "Stop"


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
D

DS

This seems to work as well...

Dim tmp As Currency
tmp = Int((myNum / X) * 100) / 100
MsgBox tmp
If tmp = 0# Then
MsgBox "Stop"
Else
'Run Code
End If

Thanks
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top