Interesting functions

Formatting numbers

Get the decimal separator

Dim DecimalSeparator As Char = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator

Output

According to current regional settings
Imports System.Globalization
Standard: .ToString(CultureInfo.CurrentCulture)
In a certain format: .ToString(Format, IFormatprovider)
Example: .ToString("#0.00", CultureInfo.CurrentCulture)

According to specific regional settings
.ToString(New CultureInfo("en-US")) 'Belgiƫ: nl-BE

To SQL server
.ToString(CultureInfo.InvariantCulture)

Convert nullable to not nullable type

numberNotNullable = numberNullable.Value

Input

According to the current regional settings
decimal.TryParse(string, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, decimal)

According to specific regional settings
decimal.TryParse(string, NumberStyles.AllowDecimalPoint, New CultureInfo("en-us"), decimal)

Specifying decimal separator
Overview

Examples of IFormatProviders

DateTime
d Format Specifier en-US Culture 10/1/2008
D Format Specifier en-US Culture Wednesday, October 01, 2008
f Format Specifier en-US Culture Wednesday, October 01, 2008 5:04 PM
F Format Specifier en-US Culture Wednesday, October 01, 2008 5:04:32 PM
g Format Specifier en-US Culture 10/1/2008 5:04 PM
G Format Specifier en-US Culture 10/1/2008 5:04:32 PM
m Format Specifier en-US Culture October 01
o Format Specifier en-US Culture 2008-10-01T17:04:32.0000000
r Format Specifier en-US Culture Wed, 01 Oct 2008 17:04:32 GMT
s Format Specifier en-US Culture 2008-10-01T17:04:32
t Format Specifier en-US Culture 5:04 PM
T Format Specifier en-US Culture 5:04:32 PM
u Format Specifier en-US Culture 2008-10-01 17:04:32Z
U Format Specifier en-US Culture Thursday, October 02, 2008 12:04:32 AM
Y Format Specifier en-US Culture October, 2008

Number
16325.62901
G "eu-ES" Displays: 16325,62901
G "en-US" Displays: 16325.62901
C "en-US" Displays: $16,325.63
C "en-GB" Displays: 16,325.63
E04 "sv-SE" Displays: 1,6326E+004
E04 "en-NZ" Displays: 1.6326E+004
F "fr-FR" Displays: 16325,63
F "en-CA" Displays: 16325.63
N "es-ES" Displays: 16.325,63
N "fr-CA" Displays: 16 325,63
P CultureInfo.InvariantCulture Displays: 163.26 %
P "ar-EG" Displays: 163.256 %

More info

Other string functions

Split up string

Dim strLayout As String()
strLayout = Value.Split(New Char() {"#"c})

VBA: Function Split(ByVal Expression As String, Optional ByVal Delimiter As String = " ", Optional ByVal Limit As Integer = -1, Optional ByVal Compare As CompareMethod = CompareMethod.Binary) As String()

Date/time functions

VBA date tricks

Reference
'Get first and last of the month
datFirstOfMonth = DateSerial(intYear, intMonth, 1)
datLastOfMonth = DateSerial(intYear, intMonth + 1, 0)

ISO standard 8601 states that week number 1 is the week containing the first thursday of the year.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License