Visual Basic Helper Routines
VarMonthName: Retrieve Localized Month 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


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
One of the operating systems listed above.

The VarMonthName API contained in oleaut32.dll provides a rapid way to retrieve both short or long month names based on the current system locale.

The iMonth parameter accepts a value between 1 and 12, while the fAbbrey param is a flag indicating whether the long month (i.e. January) or the abbreviated month (i.e. Jan) is returned. dwFlags is essentially ignored, as its only value can be VAR_CALENDAR_HIJRI.  The month name corresponding to the value set in iMonth is returned as pbstrOut.

 BAS Module Code

 Form Code
To a form, add a command button (Command1), a list box (List1) 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 VarMonthName Lib "oleaut32" _
  (ByVal iMonth As Long, _
   ByVal fAbbrey As Long, _
   ByVal dwFlags As Long, _
   pbstrOut As String) As Long

Private Sub Command1_Click()

   Dim cnt As Long
   Dim result As String
   Dim fAbbreviate As Long
   fAbbreviate = GetSelectedOptionIndex()
   For cnt = 1 To 12
     'pad a buffer for the return value,
     'which is returned as a Unicode string
      result = Space$(32)
      Call VarMonthName(cnt, fAbbreviate, 0&, result)
      List1.AddItem StrConv(result, vbFromUnicode)
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



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