Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGet day, month, date, time, and number format information for the computer's locale in Visual Basic 2005
DescriptionThis example shows how to get day, month, date, time, and number format information for the computer's locale in Visual Basic 2005.
Keywordsday, month, date, time, number, percent, format, locale, VB.NET
CategoriesMiscellany, Software Engineering
 
The My.Computer.Info.InstalledUICulture namespace leads to lots of information about the computer's numeric, date, and time formatting. This example adds a bunch of these values to a ListView control. The following code shows how the program adds just a few of the values.
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ' Day/Month values.
    AddHeader("Day/Month")
    AddArrayItems("Day", _
        My.Computer.Info.InstalledUICulture.DateTimeFormat.DayNames)
    AddArrayItems("Abbrev Day", _
        My.Computer.Info.InstalledUICulture.DateTimeFormat.AbbreviatedDayNames)
    ...

    ' Date/Time values.
    AddHeader("Date/Time Format")
    AddItem("AMDesignator", _
        My.Computer.Info.InstalledUICulture.DateTimeFormat.AMDesignator)
    AddItem("DateSeparator", _
        My.Computer.Info.InstalledUICulture.DateTimeFormat.DateSeparator)
    AddItem("FirstDayOfWeek", _
        My.Computer.Info.InstalledUICulture.DateTimeFormat.FirstDayOfWeek)
    ...

    ' Currency values.
    AddHeader("Currency Format")
    AddItem("Decimal Digits", _
        My.Computer.Info.InstalledUICulture.NumberFormat.CurrencyDecimalDigits)
    AddItem("Decimal Separator", _
        My.Computer.Info.InstalledUICulture.NumberFormat.CurrencyDecimalSeparator)
    AddItem("Group Separator", _
        My.Computer.Info.InstalledUICulture.NumberFormat.CurrencyGroupSeparator)
    AddIntegerArrayItems("Group Size", _
        My.Computer.Info.InstalledUICulture.NumberFormat.CurrencyGroupSizes)
    ...

    lvwValues.Columns(0).Width = -2
    lvwValues.Columns(1).Width = -2

    ' Make it really tall.
    Me.Top = 0
    Me.Height = My.Computer.Screen.WorkingArea.Height
End Sub
 
Helper routines add different kinds of values to the ListView control.
 
' Add a header row.
Private Sub AddHeader(ByVal name As String)
    Dim lvi As ListViewItem = lvwValues.Items.Add(name)
    lvi.BackColor = Color.Pink
End Sub
 
' Add a value to the result.
Private Sub AddItem(ByVal name As String, ByVal value As _
    String)
    Dim lvi As ListViewItem = lvwValues.Items.Add(name)
    lvi.SubItems.Add(value)
End Sub

' Add all values in an array.
Private Sub AddArrayItems(ByVal name As String, ByVal _
    values() As String)
    For i As Integer = 0 To values.Length - 1
        AddItem(name & "(" & i & ")", values(i))
    Next i
End Sub

' Add all values in an integer array.
Private Sub AddIntegerArrayItems(ByVal name As String, _
    ByVal values() As Integer)
    For i As Integer = 0 To values.Length - 1
        AddItem(name & "(" & i & ")", values(i))
    Next i
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated