function for getting value of a month - vb6

In VB6 is there a function that returns the value of what month it is?

For example

January would equal 1 and February would equal 2, etc...
al4629740Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul JacksonSoftware EngineerCommented:
Month() returns an integer value representing the month of a given date/time
So you can use Month(Now) to get the month of the current date.
0
al4629740Author Commented:
Month(January) returns 1?
0
Paul JacksonSoftware EngineerCommented:
No you have to pass in a DateTime value to the Month function.

If you want a function to return an integer value based on text passed in, just write it yourself like :

Called using :
GetMonthInteger("January")

Function GetMonthInteger(ByVal textMonth as String) As Integer
    Dim iMonth As Integer = 0
    ' convert the passed in text to lower case
    Dim month as String = LCase$(textMonth)
    ' convert text month to integer value
    Select Case Date_Str
        Case "january"
            iMonth = 1
        Case "february"
            iMonth = 2
        Case "march"
            iMonth = 3
        Case "april"
            iMonth = 4
        Case "may"
            iMonth = 5
        Case "june"
            iMonth = 6
        Case "july"
            iMonth = 7
        Case "august"
            iMonth = 8
        Case "september"
            iMonth = 9
        Case "october"
            iMonth = 10
        Case "november"
            iMonth = 11
        Case "december"
            iMonth = 12
    End Select
    Return iMonth
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
Tweaking Paul's solution a bit because you don't need iMonth and it wouldn't compile anyhow because the Dim assigning a value is not valid for VB6 gives you this.

Function GetMonthInteger(ByVal textMonth as String) As Integer

    ' convert text month to integer value
    Select Case lcase(textMonth)
        Case "january"
            GetMonthInteger = 1
        Case "february"
            GetMonthInteger = 2
        Case "march"
            GetMonthInteger = 3
        Case "april"
            GetMonthInteger = 4
        Case "may"
            GetMonthInteger = 5
        Case "june"
            GetMonthInteger = 6
        Case "july"
            GetMonthInteger = 7
        Case "august"
            GetMonthInteger = 8
        Case "september"
            GetMonthInteger = 9
        Case "october"
            GetMonthInteger = 10
        Case "november"
            GetMonthInteger = 11
        Case "december"
            GetMonthInteger = 12
        Case Else
            Msgbox "Unknown month"
            GetMonthInteger = -1 
    End Select
    
End Function

Open in new window

0
Martin LissOlder than dirtCommented:
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.