What's wrong with this very simple code

Ajayi32

Registered User.
Local time
Today, 21:43
Joined
Feb 21, 2001
Messages
26
It keeps saying there is a syntax error on line 3. Why? Thanks in advance

Function AutoFail(CSEVal97, CSEVal98, CSEVal99)
If CSEVal97 = 0 Then
AutoFail = 0
Else
AutoFail = CSEVal98 + CSEVal99
End if
End function
 
It keeps saying there is a syntax error on line 3. Why? Thanks in advance

Function AutoFail(CSEVal97, CSEVal98, CSEVal99)
If CSEVal97 = 0 Then
AutoFail = 0
Else
AutoFail = CSEVal98 + CSEVal99
End if
End function

My guess is that you haven't dim'd AutoFail.
 
You need to declare the type for the function:

Function AutoFail(CSEVal97, CSEVal98, CSEVal99) as Integer
If CSEVal97 = 0 Then
AutoFail = 0
Else
AutoFail = CSEVal98 + CSEVal99
End if
End function
 
you may also get problems depending on the type/value of the arguments ie especially if any of them are null
 
you may also get problems depending on the type/value of the arguments ie especially if any of them are null

Very true. I was a bit hasty in answering. A better syntax would be:

Function AutoFail(CSEVal97 as Integer, CSEVal98 as Integer, CSEVal99 as Integer) as Integer
If CSEVal97 = 0 Then
AutoFail = 0
Else
AutoFail = CSEVal98 + CSEVal99
End if
End function

You should test your input for nulls before calling the function.
 

Users who are viewing this thread

Back
Top Bottom