Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays

Status
Not open for further replies.

slwolf8

Technical User
Apr 23, 2001
82
US
I would like to create an array of months to populate a several combo boxes on my forms. (I know that there is a calendar control but we have had a problem with this at work with it showing up as a missing reference on some user's machines) I know how to do an array for the days:

Dim index as variant (not sure if that is the right data type)
For index 1 to 31
cboDay.additem index
Next

But I can't figure out all the steps for the months. I think I need to start out with:

Dim Months(11) as variant
Month(0) = "January"....

But then how do I "call" that set to populate the combo box?
 
Some useful stuff:

[tt]Dim iLastDay(12) As Integer, sMonth(12) As String
theYear = 2003
For i = 1 To 12
iLastDay(i) = Day(DateSerial(theYear, i + 1, 0))
sMonth(i) = Format(DateSerial(2003, i, 1), "mmmm")
Next i
cmbMonth.List = sMonth[/tt]

iLastDay(i) keeps the last day of month i of theYear (here 2003),
sMonth(i) has full system month names,
cmbMonth.List = sMonth assigns full months list to combo box named cmbMonth.

Hope this will be useful.

combo

 
This is a great start for me, honestly though I am having trouble understanding it all. I am looking in the help file on vb constants (this is new to me). I don't see anything that is called sMonth. Any more tips? Thanks!
 
iLastDay(12) is my integer array where I store number of last day of month, sMonth(i) is my string array to keep month names.
Day(DateSerial(theYear, i + 1, 0)) takes the 0 day of month i+1, i.e. last day of month i.
I have not used calculated last day, but it is useful information for a calendar based on drop-downs.

Format(DateSerial(...),"mmmm") - creates date with day 1 of month i and year 2003 and returns it in a string format "mmmm", i.e. full month name.

Day, DateSerial and Format functions can be found in vb help files.

combo
 
What's the definition of 'system month'? My system language is not English, but executing Format(DateSerial(...),"mmmm") returns month names in English. Where are these month names coming from?
 
krind,
on my PC (win 2k, office xp) the month's name language returned by Format(...) is the same as language seting in 'Regional settings' (control panel). And changes when I change the language. It is both for VBA (non-English office) and VB (English).

combo
 
combo,
Strange, b/c my regional settings stipulate Japanese, and the sample text/date/times/etc all come out in Japanese. Anyhow, what's you said is sound, so it looks like it's a settings issue on my side. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top