Results 1 to 6 of 6

Thread: International dayNames

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    International dayNames

    International dayNames
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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

  3. #3

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: International dayNames

    here it is with comments. HTH:

    vb Code:
    1. Imports System.Globalization
    2.  
    3. Public Class Form1
    4.  
    5. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.     'create new datatable
    7.     Dim dt As New DataTable
    8.     'add 7 columns for dayNames() (0 to 6 = sunday to saturday)
    9.     dt.Columns.Add("0")
    10.     dt.Columns.Add("1")
    11.     dt.Columns.Add("2")
    12.     dt.Columns.Add("3")
    13.     dt.Columns.Add("4")
    14.     dt.Columns.Add("5")
    15.     dt.Columns.Add("6")
    16.     'add a column for the EnglishName of the culture
    17.     dt.Columns.Add("cultureName")
    18.  
    19.     'for each individual culture
    20.     For Each ci As CultureInfo In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
    21.         'create a new list + add DayNames() + EnglishName
    22.         Dim fields As New List(Of String)(New CultureInfo(ci.Name).DateTimeFormat.DayNames)
    23.         fields.Add(ci.Parent.EnglishName)
    24.         'add a new row to the datatable containing the contents of the fields list
    25.         Dim dr As DataRow = dt.NewRow
    26.         dr.ItemArray = fields.ToArray
    27.         dt.Rows.Add(dr)
    28.     Next
    29.  
    30.     'select distinct rows from the datatable
    31.     dt = dt.DefaultView.ToTable(True, New String() {"cultureName", "0", "1", "2", "3", "4", "5", "6"})
    32.     'remove unwanted rows from the datatable
    33.     For x As Integer = dt.Rows.Count - 1 To 0 Step -1
    34.         If dt.Rows(x).Item("cultureName").ToString = "Invariant Language (Invariant Country)" Then
    35.             dt.Rows.Remove(dt.Rows(x))
    36.         End If
    37.     Next
    38.  
    39.     'setup the databindings
    40.     ComboBox1.DisplayMember = "cultureName"
    41.     ComboBox1.DataSource = dt
    42.  
    43.     TextBox1.DataBindings.Add("Text", dt, "0") 'sunday
    44.     TextBox2.DataBindings.Add("Text", dt, "1") 'monday
    45.     TextBox3.DataBindings.Add("Text", dt, "2") 'tuesday
    46.     TextBox4.DataBindings.Add("Text", dt, "3") 'wednesday
    47.     TextBox5.DataBindings.Add("Text", dt, "4") 'thursday
    48.     TextBox6.DataBindings.Add("Text", dt, "5") 'friday
    49.     TextBox7.DataBindings.Add("Text", dt, "6") 'saturday
    50.  
    51. End Sub

  4. #4
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    965

    Re: International dayNames

    Quote Originally Posted by .paul. View Post
    here it is with comments. HTH:

    vb Code:
    1. Imports System.Globalization
    2.  
    3. Public Class Form1
    4.  
    5. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.     'create new datatable
    7.     Dim dt As New DataTable
    8.     'add 7 columns for dayNames() (0 to 6 = sunday to saturday)
    9.     dt.Columns.Add("0")
    10.     dt.Columns.Add("1")
    11.     dt.Columns.Add("2")
    12.     dt.Columns.Add("3")
    13.     dt.Columns.Add("4")
    14.     dt.Columns.Add("5")
    15.     dt.Columns.Add("6")
    16.     'add a column for the EnglishName of the culture
    17.     dt.Columns.Add("cultureName")
    18.  
    19.     'for each individual culture
    20.     For Each ci As CultureInfo In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
    21.         'create a new list + add DayNames() + EnglishName
    22.         Dim fields As New List(Of String)(New CultureInfo(ci.Name).DateTimeFormat.DayNames)
    23.         fields.Add(ci.Parent.EnglishName)
    24.         'add a new row to the datatable containing the contents of the fields list
    25.         Dim dr As DataRow = dt.NewRow
    26.         dr.ItemArray = fields.ToArray
    27.         dt.Rows.Add(dr)
    28.     Next
    29.  
    30.     'select distinct rows from the datatable
    31.     dt = dt.DefaultView.ToTable(True, New String() {"cultureName", "0", "1", "2", "3", "4", "5", "6"})
    32.     'remove unwanted rows from the datatable
    33.     For x As Integer = dt.Rows.Count - 1 To 0 Step -1
    34.         If dt.Rows(x).Item("cultureName").ToString = "Invariant Language (Invariant Country)" Then
    35.             dt.Rows.Remove(dt.Rows(x))
    36.         End If
    37.     Next
    38.  
    39.     'setup the databindings
    40.     ComboBox1.DisplayMember = "cultureName"
    41.     ComboBox1.DataSource = dt
    42.  
    43.     TextBox1.DataBindings.Add("Text", dt, "0") 'sunday
    44.     TextBox2.DataBindings.Add("Text", dt, "1") 'monday
    45.     TextBox3.DataBindings.Add("Text", dt, "2") 'tuesday
    46.     TextBox4.DataBindings.Add("Text", dt, "3") 'wednesday
    47.     TextBox5.DataBindings.Add("Text", dt, "4") 'thursday
    48.     TextBox6.DataBindings.Add("Text", dt, "5") 'friday
    49.     TextBox7.DataBindings.Add("Text", dt, "6") 'saturday
    50.  
    51. 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?

  5. #5
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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

  6. #6

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Thumbs up Re: International dayNames

    Quote Originally Posted by NickThissen View Post
    By the way paul, thanks for this. I didn't know this information was available this easily.
    no problem...

    Quote Originally Posted by NickThissen View Post
    I'm using it for a month calendar control I'm creating, so now I can make it culture specific.
    good idea

    Quote Originally Posted by NickThissen View Post
    The DateTimeFormat also specifies other things such as month names, abbreviated day and month names, first day of the week, etc.
    yeah i know

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width