Visual Basic Helper Routines
VarWeekdayName: Retrieve Localized Weekday Names
     
Posted:   Monday October 01, 2001
Updated:   Monday December 26, 2011
     
Applies to:   VB5, VB6
Developed with:   VB6, Windows XP
OS restrictions:   Windows NT4 SP4 or later, Windows 98 or later, or Windows 95 with DCOM 1.2
Author:   VBnet - Randy Birch
       

Related:  

Pure VB: Methods to Determine the Last Day of the Month
Pure VB: Methods to Determine Number of Days in a Month
Pure VB: Determining Leap Years
VarMonthName: Retrieve Localized Month Names
VarWeekdayName: Retrieve Localized Weekday Names
     
 Prerequisites
One of the operating systems listed above.

VarWeekdayName in oleaut32.dll provides a rapid way to retrieve both short or long weekday names based on the current system locale.

The iWeekday parameter accepts a value between 1 and 7 representing the day of interest. The iFirstDay parameter indicates which day of the week is considered the first day of the week in generating the dates.  For example, if iWeekday is 1, and iFirstDay is 1, the date returned is Sunday.  If iFirstDay was 5, the date returned would be Thursday.  The fAbbrey flag indicates whether the long weekday name (i.e. Wednesday) or the abbreviated day (i.e. Wed) is returned. dwFlags is essentially ignored, as its only value can be VAR_CALENDAR_HIJRI.  The weekday corresponding to the value set in iWeekday is returned as pbstrOut.

 BAS Module Code
None.

 Form Code
To a form, add a command button (Command1), a list box (List1), a combo box (Combo1) and two option buttons (Option1(0) and Option1(1), along with the following code:

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit

Private Declare Function VarWeekdayName Lib "oleaut32" _
  (ByVal iWeekday As Long, _
   ByVal fAbbrey As Long, _
   ByVal iFirstDay As Long, _
   ByVal dwFlags As Long, _
   pbstrOut As String) As Long


Private Sub Form_Load()

   Dim c As Long
   
   For c = 1 To 7
      Combo1.AddItem c
   Next
   
   Combo1.ListIndex = 0
   
End Sub


Private Sub Command1_Click()

   Dim cnt As Long
   Dim result As String
   Dim fAbbreviate As Long
   Dim fFirstDay As Long
   
   fAbbreviate = GetSelectedOptionIndex()
   
  'set the first day of the week
   fFirstDay = CLng(Combo1.List(Combo1.ListIndex))
   
   List1.Clear
   
   For cnt = 1 To 7
      
     'pad a buffer for the return value,
     'which is returned as a Unicode string
      result = Space$(32)
      Call VarWeekdayName(cnt, fAbbreviate, fFirstDay, 0&, result)
      List1.AddItem StrConv(result, vbFromUnicode)
      
   Next
   
End Sub


Private Function GetSelectedOptionIndex() As Long

  'returns the selected item index from
  'an option button array. Use in place
  'of multiple If...Then statements!
  'If your array contains more elements,
  'just append them to the test condition,
  'setting the multiplier to the button's
  'negative -index.
   GetSelectedOptionIndex = Option1(0).Value * 0 Or _
                            Option1(1).Value * -1
End Function

 Comments

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter