![]() |
Calling a Custom Function within a Procedure
I am trying to call a function within a procedure. I can't seem to
get it to work. What am I doing wrong. Here is the function: Private Function IsLeapYear(Y As Integer) IsLeapYear = Month(DateSerial(Y, 2, 29)) = 2 End Function Here is the Procedu Sub Simulation() Dim BeginningYear As Integer BeginningYear = 2003 If IsLeapYear(BeginningYear) = True Then HoursinYear = 8784 Else: HoursinYear = 8760 End If End Sub I keep getting an error message saying "Compile Error:Expected Array". It then highlights the "IsLeapYear" within my If statement. Can anyone tell me what I am doing wrong? TS |
Calling a Custom Function within a Procedure
Your syntax is screwed up. Your if statement is written like a single line
if statement. You either need to move the command to the next line or put in a statement separator character (you haven't gotten to that error yet) If IsLeapYear(BeginningYear) = True Then: HoursinYear = 8784 Else: HoursinYear = 8760 End If or If IsLeapYear(BeginningYear) = True Then HoursinYear = 8784 Else: HoursinYear = 8760 End If The expected array would be because IsLeapYear function isn't visible to your main procedure - You apparently have it in a separate module and since you made it private, it can't be seen in this module so it looks like an array in your statement. IsLeapYear must be in the same module if you make it private. -- Regards, Tom Ogilvy wrote in me ssage om... I am trying to call a function within a procedure. I can't seem to get it to work. What am I doing wrong. Here is the function: Private Function IsLeapYear(Y As Integer) IsLeapYear = Month(DateSerial(Y, 2, 29)) = 2 End Function Here is the Procedu Sub Simulation() Dim BeginningYear As Integer BeginningYear = 2003 If IsLeapYear(BeginningYear) = True Then HoursinYear = 8784 Else: HoursinYear = 8760 End If End Sub I keep getting an error message saying "Compile Error:Expected Array". It then highlights the "IsLeapYear" within my If statement. Can anyone tell me what I am doing wrong? TS |
All times are GMT +1. The time now is 06:24 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com