Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Year() problem 1

Status
Not open for further replies.

ckeener

Programmer
Dec 2, 2003
53
US
I have a piece of code that is giving me problems using the Year() function. I get an error telling me that an array was expected. I have looked at several examples and it appears I am using it correctly. This is a condensation of the code I am having problems with.
Code:
Public Function IsDST(Year As String) As Boolean
    IsDST = False

    Dim DateToView As Date
    Dim BeginDate As Date
    Dim EndDate As Date
    Dim MonthToView As Integer
    Dim YearToView As Integer
    Dim DayToView As Integer
    Dim CheckDay As Integer

    DateToView = StartDate
    MonthToView = 4
    [b]YearToView = Year(DateToView)[/b]
    DayToView = 1
*
*
*
*
    If (DateToView > EndDate) Or (DateToView < BeginDate) Then IsDST = True
    
End Function

the line - YearToView = Year(DateToView) seems to be where I get the "expected array" error.

Am I doing something wrong...does anyone have any ideas.

Thanks

(I can post the entire code if it would help)
 
Two things I see from the code:
1 - you're passing a string variable having the name of a function (year) which you use on the DateToView variable - bound to give headaches, it might be related to this headache
2 - what is the datatype and value of DateToView?

Roy-Vidar
 
Roy-Vidar,

The first problem that you found was what was wrong with my code. Sometimes its hard to see the forest for the trees. Thanks here is the code listing corrected.

Code:
Public Function IsDST(DateIn As String) As Boolean
    IsDST = False
    
    'If (Year < 1950) Then Exit Function
    
    Dim DateToView As Date
    Dim BeginDate As Date
    Dim EndDate As Date
    Dim MonthToView As Integer
    Dim YearToView As Integer
    Dim DayToView As Integer
    Dim CheckDay As Integer
    
    DateToView = DateIn
    MonthToView = 4
    YearToView = Year(DateToView)
    DayToView = 1
    
    Do While Weekday(DayToView & "/" & MonthToView & "/" & YearToView) <> vbSunday
        DayToView = DayToView + 1
    Loop
    
    BeginDate = (DayToView & "/" & MonthToView & "/" & YearToView)
    
    MonthToView = 10
    DayToView = 31
    
    Do While Weekday(DayToView & "/" & MonthToView & "/" & YearToView) <> vbSunday
        DayToView = DayToView - 1
    Loop
    
    
    EndDate = (DayToView & "/" & MonthToView & "/" & YearToView)
    
    If (DateToView > EndDate) Or (DateToView < BeginDate) Then IsDST = True
    
End Function

 
I think you have to play with the IsDate and CDate functions.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top