Format Function & User-Defined Formats

 

Format ( ) returns a variant datatype formatted to look the way you'd like it to. Below is a list of possible format values.

Basic Form:

    VarName = Format (Expression, strFormat )

 

Where,

  • Expression can be a variable, an expression, or a constant.
  • strFormat can take on the following values: 

strFormat

Description

Currency

Displays the number with a $ and the appropriate thousands separator. Negative values are displayed in parentheses.

Fixed

Displays at least one digit before and two digits after the decimal point without the thousands separator (,)

General Number

Displays a number without a thousands separator (,)

Medium Time

Displays time in 12-hour format and the AM and PM

indicator

On/Off

Displays "On" if the value contains nonzero or a true value. Displays "Off" if the value contains zero or a False value

Percent

Displays number as a percent

Scientific

Displays number in scientific notation

Short Time

Displays time in 24-hour format

True/False

Displays "True" if the value contains nonzero or a true value. Displays "False" if the value contains zero or a False value

Yes/No

Displays "Yes" if the value contains nonzero or a true value. Displays "No" if the value contains zero or a False value

 

Defining Your Own Formatting Codes

You can define your own formatting codes, using the Format ( ) Function without the strFormat, using what are referred to as Edit Masks. An Edit Mask looks like this:

 

    varName = Format(argument, "###,###.0000")

 

The Edit Mask consists of # signs, zeros, comma, periods, and other characters. Each # sign indicates where a digit should go and zeros indicate the number of leading or trailing zeros desired. If you omit the decimal point, no decimal point will be displayed. If you omit the commas, no thousands separator will be displayed.

Back to Top

arrowl2Return to the Visual Basic Page

Comments

 

Latest Version! NetObjects Fusion 10 

 

Copyright 1998 Rich Hamper 

All Rights Reserved

 

Last Updated:

Sunday, January 20, 2008