[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# function for getting value of a month - vb6

Posted on 2014-08-01
Medium Priority
185 Views
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...
0
Question by:al4629740
• 2
• 2

LVL 29

Expert Comment

ID: 40235626
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

Author Comment

ID: 40236259
Month(January) returns 1?
0

LVL 29

Accepted Solution

Paul Jackson earned 1600 total points
ID: 40236398
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
``````
0

LVL 50

Assisted Solution

Martin Liss earned 400 total points
ID: 40236569
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
``````
0

LVL 50

Expert Comment

ID: 40236593
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
###### Suggested Courses
Course of the Month17 days, 23 hours left to enroll