Different Formats for Different Numeric Values (Format Function)

A user-defined format expression for numbers can have from one to three sections separated by semicolons. If the Style argument of the Format function contains one of the predefined numeric formats, only one section is allowed.

If you use

This is the result

One section only

The format expression applies to all values.

Two sections

The first section applies to positive values and zeros; the second applies to negative values.

Three sections

The first section applies to positive values, the second applies to negative values, and the third applies to zeros.

The following example has two sections: the first defines the format for positive values and zeros; the second section defines the format for negative values. Since the Style argument of the Format function takes a string, it is enclosed by quotation marks.

Dim Style1 As String = "$#,##0;($#,##0)"

If you include semicolons with nothing between them, the missing section is printed using the format of the positive value. For example, the following format displays positive and negative values using the format in the first section and displays Zero if the value is zero.

Dim Style2 As String = "$#,##0;;\Z\e\r\o"

Requirements

Namespace:Microsoft.VisualBasic

**Module:**Strings

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also

Reference

Predefined Numeric Formats (Format Function)

Format Function

String Manipulation Summary