12-19-2001, 10:42 AM
I need help on putting a code into a program that firgures precent I had one but everytime that I ran it and a zero was in the program it would stop I know that you can not divide by zero but if a zero get into the program by mistake it will not run I need a if statement to get around this so that if a zero get into it then in the total box it will still say 0% and keep on running I am a newbie at this

12-19-2001, 10:50 AM
Try this on a form with text1, text2 and Command1

Private Function DoPercent(dInNum As Double) As Double
If dInNum = 0 Then
DoPercent = 0#
DoPercent = dInNum / 100
End If
End Function

Private Sub Command1_Click()
Text2 = Format(DoPercent(Text1), "Percent")
End Sub

12-19-2001, 11:07 AM
Actually, his problem is Divide By Zero, so you'd need something like this:

Function CalcPercent(X as Single, Total as Single) as Single
Dim Result as Single
If Total = 0 Then
Result = 0
Result = X * 100 / Total
End If

CalcPercent = Result

End Function


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum