Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run external workbook function/procedure? Vinod Excel Discussion (Misc queries) 3 August 10th 09 02:03 PM
Calling a function in my SQL-DB from VBA KSor Excel Discussion (Misc queries) 0 March 11th 09 02:08 PM
Create a procedure or function Alexandra Lopes Excel Worksheet Functions 0 November 19th 08 10:00 AM
Calling procedure when leaving cell jeffP Excel Worksheet Functions 5 February 9th 06 08:59 AM


All times are GMT +1. The time now is 03:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"