Format: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
C185driver (talk | contribs)
No edit summary
Line 1: Line 1:
FormatCurrency(''expression''[, ''fractionaldigits''[, ''leadingdigit''[, ''parensfornegative''[, ''groupdigits'']]]])
Format(''string'', ''replace0''[,''replace1''...])
 
FormatDateTime(''date''[, ''formatname''])
 
FormatNumber(''expression''[, ''fractionaldigits''[, ''leadingdigit''[, ''parensfornegative''[, ''groupdigits'']]]])
 
FormatPercent(''expression''[, ''fractionaldigits''[,''leadingdigit''[, ''parensfornegative''[, ''groupdigits'']]]])
 


== Description ==
== Description ==


FormatCurrency, FormatNumber, and FormatPercent return a string obtained by formatting the given expression as a currency, number, or percent. The required parameter, ''expression'', is any valid expression of the given type.
Replaces {n} placeholders with arguments. One or more arguments can be passed, in addition to the string template itself, to insert into the string.
 
The optional parameter, ''fractionaldigits'', is a numeric expression representing the number of digits to print after the decimal. The default is -1 which uses the system settings.
 
The optional parameters, ''leadingdigit'', ''parensfornegative'', and ''groupdigits'', are tristate values. See table below.
 
''leadingdigit'' specifies whether a leading zero is printed for numbers with only fractional parts.
 
''parensfornegative'' specifies if negative values are to be printed with enclosing parentheses.
 
''groupdigits'' specifies if numbers are to be printed in groups using the systems group delimiter.
 
'''Tristate values'''
 
{| class="wikitable"
|-
! Name !! Value !! Description
|-
| True || -1 || True
|-
| False || 0 || False
|-
| TriStateUseDefault || -2 || Use system settings
|}
 
FormatDateTime returns a string obtained by formatting a date. The required parameter, ''date'', is any valid expression that represents a date. The optional parameter, ''formatname'', is a numeric expression or constant that specifies how the date is formatted.
 
'''formatname constants'''
 
{| class="wikitable"
|-
! Constant !! Value !! Description !! Sample
|-
| vbGeneralDate || 0 || Short date, Long time || 10/30/2013 00:05:57 PM
|-
| vbLongDate || 1 || Long date || Wednesday, October 30, 2013
|-
| vbShortDate || 2 || Short date || 10/30/2013
|-
| vbLongTime || 3 || Long time || 00:05:57 PM
|-
| vbShortTime || 4 || Short time || 17:57
|-
| vbYYYYMMDD || 5 ||  || 20131030
|-
| vbDDdotMMdotYY || 6|| || 30.10.13
|-
| vbDDdotMMdotYYYY || 7 ||  || 30.10.2013
|-
| vbYYslashMMslashDD || 8 ||  || 13/10/30
|-
| vbDDslashMMslashYY || 9 ||  || 30/10/13
|-
| vbYYYYhyphenMMhyphenDD || 10 ||  || 2013-10-30
|}
 
The following are also allowed as ''format name'':
"DD.MM.YY", "DD.MM.YYYY", "DD/MM/YY", "DD/MM/YYYY", "DD-MM-YY", "DD-MM-YYYY", "DDMMYY", "DDMMYYYY", "YY.MM.DD", "YYYY.MM.DD", "YY/MM/DD", "YYYY/MM/DD", "YY-MM-DD", "YYYY-MM-DD", "YYMMDD", "YYYYMMDD", "MM.DD.YY", "MM.DD.YYYY", "MM/DD/YY", "MM/DD/YYYY", "MM-DD-YY", "MM-DD-YYYY", "MMDDYY", "MMDDYYYY",
 
== Example (Basic) ==
== Example (Basic) ==


<pre>
<pre>
Rem Format Functions
Print Format("1{0}2","a")
Dim UseDefault
Print Format("My name is {0} and I live in {1}.", "Kartman", "South Park")
UseDefault=-2
'Currency
Print FormatCurrency(-3.5, -1, TristateUseDefault, True)
Print FormatCurrency(123456, 0,True, False, True)
'Date/Time
Print FormatDateTime(Now)
Print FormatDateTime(Birthdate, vbLongDate)
'General Numbers
Print FormatNumber(-0.1429, 6,False)
Print FormatNumber(987654.321, 3, True, False, True)
'Percentages
Print FormatPercent(0.007, 2, False)
Print FormatPercent(1234.56, 0,True, False, False)
</pre>
</pre>


Line 97: Line 19:
== Output ==
== Output ==
<pre>
<pre>
($3.50)
1a2
$123,456
My name is Kartman and I live in South Park.
8/18/1998 10:44 PM
August 18, 1998
-.142900
987,654.321
.70%
123456%
(sample output is system dependant)
</pre>
</pre>



Revision as of 16:39, 2 April 2014

Format(string, replace0[,replace1...])

Description

Replaces {n} placeholders with arguments. One or more arguments can be passed, in addition to the string template itself, to insert into the string.

Example (Basic)

Print Format("1{0}2","a")
Print Format("My name is {0} and I live in {1}.", "Kartman", "South Park")

Example (JavaScript)

NSB.Print(FormatCurrency(-3.5, 2, 0, true));
NSB.Print(FormatCurrency(123456, 2, true, false, true));

Output

1a2
My name is Kartman and I live in South Park.