Click to See Complete Forum and Search --> : How to get a list of Weeks, Months and Country


microbeam
02-13-2004, 02:59 AM
I am a beginner. How to get a list of Weeks, a list of Months, and a list of countries in the world or European in VB .NET?

Any information about it is helpful.


Thanks
zhiwen Hu
zhiwen_hu@hotmail.com

Phil Weber
02-13-2004, 03:32 AM
Hi, Hu: You can get the month names like this:

Dim Months() As String = System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthNames

Months(0) = "January"
Months(1) = "February"
' etc.

I don't know of any way to get a list of countries, and I don't understand what you mean by "a list of weeks."

microbeam
02-14-2004, 01:56 AM
Phil Weber,
Thanks for help. A list of weeks means the list of days of one week, such as Sunday,Monday,ect.




Thanks a lot.
Zhiwen Hu
zhiwen_hu@etang.com

Phil Weber
02-14-2004, 02:48 AM
Ah, now I understand. :)

Dim DayNames() As String = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames

microbeam
02-14-2004, 06:38 AM
Based on Phil Weber's revelation, I find a complete solution on how to get a list of month names in a year and a list of days in a week. Here, I am glad to share with you.

'To get a list of complete month names in a year
Public Sub MonthNames(ByVal cmbComboBox As ComboBox)
Dim i As Integer
Dim Months() As String = _
System.Globalization.DateTimeFormatInfo. _
CurrentInfo.MonthNames

cmbComboBox.Items.Clear()
For i = 0 To Months.Length - 2
cmbComboBox.Items.Add(Months(i))
Next
Months = Nothing
End Sub

'To get a list of abbreviated month names in a year
Public Sub AbbreviatedMonthNames(ByVal cmbComboBox As ComboBox)
Dim i As Integer
Dim Months() As String = _
System.Globalization.DateTimeFormatInfo. _
CurrentInfo.AbbreviatedMonthNames

cmbComboBox.Items.Clear()
For i = 0 To Months.Length - 2
cmbComboBox.Items.Add(Months(i))
Next
Months = Nothing
End Sub

'To get a list of complete day names in a week
Public Sub DayNames(ByVal cmbComboBox As ComboBox)
Dim i As Integer
Dim Days() As String = _
System.Globalization.DateTimeFormatInfo. _
CurrentInfo.DayNames

cmbComboBox.Items.Clear()
For i = 0 To Days.Length - 1
cmbComboBox.Items.Add(Days(i))
Next
Days = Nothing
End Sub

'To get a list of abbreviate day names in a week
Public Sub AbbreviatedDayNames(ByVal cmbComboBox As _
ComboBox)
Dim i As Integer
Dim Days() As String = _
System.Globalization.DateTimeFormatInfo. _
CurrentInfo.AbbreviatedDayNames

cmbComboBox.Items.Clear()
For i = 0 To Days.Length - 1
cmbComboBox.Items.Add(Days(i))
Next
Days = Nothing
End Sub

But maybe you notice that the value of Months.Length is 13. I have no idea about it. Could you give me hand?

Thanks

Zhiwen Hu
zhiwen_hu@hotmail.com