CST2601 Visual
Basic I
Notes on Format function
Formatting Numbers, Dates, and TimesVisual Basic provides great flexibility in displaying number formats, as well as date and time formats. You can easily display international formats for numbers, dates, and times. The Format function converts the numeric value to a text string and gives you control over the string’s appearance. For example, you can specify the number of decimal places, leading or trailing zeros, and currency formats. The syntax is: Format(expression[, format[, firstdayofweek[, firstweekofyear]]]) The expression argument specifies a number to convert, and the format argument is a string made up of symbols that shows how to format the number. The most commonly used symbols are listed in the table below.
The firstdayofweek argument is a constant that specifies the first day of the week; the firstweekofyear argument is a constant that specifies the first week of the year. Both arguments are optional. For more information about these constants, see "Format Function" in the Language Reference. Named FormatsVisual Basic provides several standard formats to use with the Format
function. Instead of designating symbols in the format argument,
you specify these formats by name in the format argument of the
Format function. Always enclose the format name in double quotation marks
( The following table lists the format names you can use.
The Format function supports many other special characters, such as the percentage placeholder and exponents. For More Information See "Format Function" in the Language Reference. Number FormatsThe following number conversions assume that the country in the Windows Control Panel is set to "English (United States)."
The symbol for the decimal separator is a period (.), and the symbol for the thousands separator is a comma (,). However, the separator character that is actually displayed depends on the country specified in the Windows Control Panel. Printing Formatted Dates and TimesTo print formatted dates and times, use the Format function with symbols representing date and time. These examples use the Now and Format functions to identify and format the current date and time. The following examples assume that the Regional Settings dialog box of the Windows Control Panel is set to "English(United States)".
By using the Now function with the format "ddddd" and "ttttt, " you can print the current date and time in a format appropriate for the selection in the Regional Settings dialog box of the Windows Control Panel.
For More Information For more information about international considerations when using the Format function, see "Locale-Aware Functions" in "International Issues. " For more information about dates based on system locale, see "Writing International Code in Visual Basic" in "International Issues. " |