I know that I can get the number of a month by feeding VB's built in MonthName function the month number
vb Code:
  1. 'returns November
  2. Msgbox MonthName(11)
However, I need to the number of the month based on its name, and I could not find anything that would give me that.

So, I wrote this function (I have the names of all 12 months in a dropdown combo).
vb Code:
  1. Private Function GetMonthNumber(pstrMonthName As String) As Integer
  2. Dim i As Integer
  3. ReDim Months(1 To 12)
  4. ReDim MonthNumber(1 To 12)
  5. Months = Array("January", "February", "March", "April", "May", "June", "July", _
  6. "August", "September", "October", "November", "December")
  7. MonthNumber = Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
  8. For i = 0 To 11
  9.     If cboMonths.Text = Months(i) Then
  10.        GetMonthNumber = MonthNumber(i)
  11.        Exit For
  12.     End If
  13. Next
  14. End Function
  15.  
  16. 'and to get the number
  17. Private Sub cboMonths_Click()
  18. Dim iMonNum As Integer
  19. iMonNum = GetMonthNumber(cboMonths.Text)
  20. MsgBox iMonNum
  21. End Sub
Works just fine but I can't help feeling I'm overlooking something.

Am I having a senior moment? There is an easier way of doing this, right?