Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleSet the Calendar control's FirstDay property correctly for this computer
DescriptionThis example shows how to set the Calendar control's FirstDay property correctly for this computer in Visual Basic 6. The program subtracts the current date's weekday number from the current day to get the first date of the week.
KeywordsWeekDayName, internationalization, first day of the week, locale
CategoriesSoftware Engineering
 
Thanks to Gary German.

The program uses DateAdd to subtract the current date's day number in days from the current date. This gives the date that is first in the week. It passes Weekday the parameter vbUseSystemDayOfWeek so it numbers the date's weekday number using the system's locale information.

The program then uses Weekday to get the date's day number, again using the parameter vbUseSystemDayOfWeek so it uses the system's locale.

Finally the program sets the Calendar control's FirstDay property to this date's number.

 
Private Sub Form_Load()
Dim first_date As Date
Dim first_day_number As Integer

    ' Get the system's first day of the week.
    first_date = DateAdd("d", -(Weekday(Date, _
        vbUseSystemDayOfWeek) - 1), Date)

    ' Convert into a day number.
    first_day_number = Weekday(first_date, _
        vbUseSystemDayOfWeek)

    ' Set the calendar's first day of the week number.
    Me.Calendar1.FirstDay = first_day_number
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated