|
-
Jun 2nd, 2011, 10:52 AM
#1
-
Jun 3rd, 2011, 06:11 AM
#2
Re: International dayNames
Cool example although, it would have been a good idea to include comments in your code so users could know how to use the code and what it happening.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jun 3rd, 2011, 08:26 AM
#3
Re: International dayNames
here it is with comments. HTH:
vb Code:
Imports System.Globalization
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'create new datatable
Dim dt As New DataTable
'add 7 columns for dayNames() (0 to 6 = sunday to saturday)
dt.Columns.Add("0")
dt.Columns.Add("1")
dt.Columns.Add("2")
dt.Columns.Add("3")
dt.Columns.Add("4")
dt.Columns.Add("5")
dt.Columns.Add("6")
'add a column for the EnglishName of the culture
dt.Columns.Add("cultureName")
'for each individual culture
For Each ci As CultureInfo In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
'create a new list + add DayNames() + EnglishName
Dim fields As New List(Of String)(New CultureInfo(ci.Name).DateTimeFormat.DayNames)
fields.Add(ci.Parent.EnglishName)
'add a new row to the datatable containing the contents of the fields list
Dim dr As DataRow = dt.NewRow
dr.ItemArray = fields.ToArray
dt.Rows.Add(dr)
Next
'select distinct rows from the datatable
dt = dt.DefaultView.ToTable(True, New String() {"cultureName", "0", "1", "2", "3", "4", "5", "6"})
'remove unwanted rows from the datatable
For x As Integer = dt.Rows.Count - 1 To 0 Step -1
If dt.Rows(x).Item("cultureName").ToString = "Invariant Language (Invariant Country)" Then
dt.Rows.Remove(dt.Rows(x))
End If
Next
'setup the databindings
ComboBox1.DisplayMember = "cultureName"
ComboBox1.DataSource = dt
TextBox1.DataBindings.Add("Text", dt, "0") 'sunday
TextBox2.DataBindings.Add("Text", dt, "1") 'monday
TextBox3.DataBindings.Add("Text", dt, "2") 'tuesday
TextBox4.DataBindings.Add("Text", dt, "3") 'wednesday
TextBox5.DataBindings.Add("Text", dt, "4") 'thursday
TextBox6.DataBindings.Add("Text", dt, "5") 'friday
TextBox7.DataBindings.Add("Text", dt, "6") 'saturday
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 8th, 2011, 12:34 AM
#4
Fanatic Member
Re: International dayNames
 Originally Posted by .paul.
here it is with comments. HTH:
vb Code:
Imports System.Globalization
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'create new datatable
Dim dt As New DataTable
'add 7 columns for dayNames() (0 to 6 = sunday to saturday)
dt.Columns.Add("0")
dt.Columns.Add("1")
dt.Columns.Add("2")
dt.Columns.Add("3")
dt.Columns.Add("4")
dt.Columns.Add("5")
dt.Columns.Add("6")
'add a column for the EnglishName of the culture
dt.Columns.Add("cultureName")
'for each individual culture
For Each ci As CultureInfo In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
'create a new list + add DayNames() + EnglishName
Dim fields As New List(Of String)(New CultureInfo(ci.Name).DateTimeFormat.DayNames)
fields.Add(ci.Parent.EnglishName)
'add a new row to the datatable containing the contents of the fields list
Dim dr As DataRow = dt.NewRow
dr.ItemArray = fields.ToArray
dt.Rows.Add(dr)
Next
'select distinct rows from the datatable
dt = dt.DefaultView.ToTable(True, New String() {"cultureName", "0", "1", "2", "3", "4", "5", "6"})
'remove unwanted rows from the datatable
For x As Integer = dt.Rows.Count - 1 To 0 Step -1
If dt.Rows(x).Item("cultureName").ToString = "Invariant Language (Invariant Country)" Then
dt.Rows.Remove(dt.Rows(x))
End If
Next
'setup the databindings
ComboBox1.DisplayMember = "cultureName"
ComboBox1.DataSource = dt
TextBox1.DataBindings.Add("Text", dt, "0") 'sunday
TextBox2.DataBindings.Add("Text", dt, "1") 'monday
TextBox3.DataBindings.Add("Text", dt, "2") 'tuesday
TextBox4.DataBindings.Add("Text", dt, "3") 'wednesday
TextBox5.DataBindings.Add("Text", dt, "4") 'thursday
TextBox6.DataBindings.Add("Text", dt, "5") 'friday
TextBox7.DataBindings.Add("Text", dt, "6") 'saturday
End Sub
hi .paul, i hope that your program run flawlessly, i haven't checked yet. Actually i am not understanding the code instead of your comments. now what i do?
-
Jun 8th, 2011, 02:20 AM
#5
Re: International dayNames
The only relevant bit is the CultureInfo.DateTimeFormat.DayNames property (line 22), which returns a string array with the names of the days in the language corresponding to that culture. Besides that, there is a loop through all cultures (line 20). The rest is just databinding to get the days into the textboxes.
By the way paul, thanks for this. I didn't know this information was available this easily. I'm using it for a month calendar control I'm creating, so now I can make it culture specific. The DateTimeFormat also specifies other things such as month names, abbreviated day and month names, first day of the week, etc. All very useful for a calendar control
-
Jun 8th, 2011, 11:08 AM
#6
Re: International dayNames
 Originally Posted by NickThissen
By the way paul, thanks for this. I didn't know this information was available this easily.
no problem...
 Originally Posted by NickThissen
I'm using it for a month calendar control I'm creating, so now I can make it culture specific.
good idea
 Originally Posted by NickThissen
The DateTimeFormat also specifies other things such as month names, abbreviated day and month names, first day of the week, etc.
yeah i know
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|