From f33281a5c92c9daa241979cd461c21f3e5cec309 Mon Sep 17 00:00:00 2001 From: Olivier Hallot Date: Wed, 14 Nov 2018 12:56:15 -0200 Subject: tdf#118473 Help page for VBA FormatNumber + some fixes in table formatting * Added Mike's advise. * fix dumb copypasta Change-Id: I997c3200e521e7fac9f20f17a9bb9e2574bccfdd Reviewed-on: https://gerrit.libreoffice.org/63373 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- source/auxiliary/sbasic.tree | 1 + source/text/sbasic/shared/03040000.xhp | 279 ++++++++++++++----------- source/text/sbasic/shared/03170010.xhp | 118 +++++++++++ source/text/sbasic/shared/special_vba_func.xhp | 5 + 4 files changed, 281 insertions(+), 122 deletions(-) create mode 100644 source/text/sbasic/shared/03170010.xhp (limited to 'source') diff --git a/source/auxiliary/sbasic.tree b/source/auxiliary/sbasic.tree index 2838f96980..d2eb5ea538 100644 --- a/source/auxiliary/sbasic.tree +++ b/source/auxiliary/sbasic.tree @@ -142,6 +142,7 @@ For...Next Statement Format Function FormatDateTime Function [VBA] +FormatNumber Function [VBA] FreeFile Function FreeLibrary Function Function Statement diff --git a/source/text/sbasic/shared/03040000.xhp b/source/text/sbasic/shared/03040000.xhp index b223fa71fd..7630de5631 100644 --- a/source/text/sbasic/shared/03040000.xhp +++ b/source/text/sbasic/shared/03040000.xhp @@ -62,24 +62,24 @@ - True + True - Boolean + Boolean - 1 + 1 - False + False - Boolean + Boolean - 0 + 0 @@ -106,13 +106,13 @@ - Pi + Pi - Double + Double - 3.14159265358979 + 3.14159265358979 @@ -140,32 +140,32 @@ - Empty + Empty - Variant + Variant - The Empty value indicates that the variable is not initialized. + The Empty value indicates that the variable is not initialized. - Null + Null - null + null - Indicates that the variable does not contain data. + Indicates that the variable does not contain data. - Nothing + Nothing - Object + Object Assign the Nothing object to a variable to remove a previous assignment. @@ -192,111 +192,146 @@ Print oDoc ‘ Error End Sub - Additional VBA constants - The following constants are available when VBA compatibility mode is enabled +
+ Additional VBA constants + The following constants are available when VBA compatibility mode is enabled - - - - - Named constant - - - Hexadecimal (decimal) value - - - Description - - - - - vbCr - - - \x0D (13) - - - CR - Carriage return - - - - - vbCrLf - - - \x0D\x0A (13 10) - - - CRLF - Carriage return and line feed - - - - - vbFormFeed - - - \x0c (12) - - - FF - Form feed - - - - - vbLf - - - \x0A (10) - - - LF - Line feed - - - - - vbNewLine - - - \x0D\x0A (13 10) for 32-bit Windows - \x0A (10) for other 64-bit systems - - - LF or CRLF - - - - - vbNullString - - - "" - - - Null string - - - - - vbTab - - - \x09 (9) - - - HT - Horizontal tab - - - - - vbVerticalTab - - - \x0B (11) - - - VT - Vertical tab - - -
+ + + + + Named constant + + + Hexadecimal (decimal) value + + + Description + + + + + vbTrue + + + -1 + + + Part of vbTriState enumeration. + + + + + vbFalse + + + 0 + + + Part of vbTriState enumeration. + + + + + vbUseDefault + + + -2 + + + Part of vbTriState enumeration. + + + + + vbCr + + + \x0D (13) + + + CR - Carriage return + + + + + vbCrLf + + + \x0D\x0A (13 10) + + + CRLF - Carriage return and line feed + + + + + vbFormFeed + + + \x0c (12) + + + FF - Form feed + + + + + vbLf + + + \x0A (10) + + + LF - Line feed + + + + + vbNewLine + + + \x0D\x0A (13 10) for 32-bit Windows + \x0A (10) for other 64-bit systems + + + LF or CRLF + + + + + vbNullString + + + "" + + + Null string + + + + + vbTab + + + \x09 (9) + + + HT - Horizontal tab + + + + + vbVerticalTab + + + \x0B (11) + + + VT - Vertical tab + + +
+
diff --git a/source/text/sbasic/shared/03170010.xhp b/source/text/sbasic/shared/03170010.xhp new file mode 100644 index 0000000000..981c15ab0d --- /dev/null +++ b/source/text/sbasic/shared/03170010.xhp @@ -0,0 +1,118 @@ + + + + + + + FormatNumber Function [VBA] + /text/sbasic/shared/03170010.xhp + + + +
+ + + FormatNumber function + + FormatNumber [VBA] + Returns a string with a number formatting applied to a numeric expression. +
+ + + FormatNumber( expression, numDigitsAfterDecimal as Integer, includeLeadingDigit as Integer,
useParensForNegativeNumbers as Integer, groupDigits as Integer )
+ + String + + + + expression: Required. The numeric expression to be formatted. + + numDigitsAfterDecimal: Optional. A numeric value specifying the number of digits that should be displayed after the decimal. If omitted, it defaults to the value -1, meaning that the default settings for user interface locale should be used.. + + includeLeadingDigit: Optional. A vbTriState enumeration value, specifying whether a leading zero should be displayed for fractional values. + + + + vbTrue or -1: Display a leading zero. + + + vbFalse or 0: Do not display leading zeros. + + + vbUseDefaults or -2: Use the user interface locale settings. This is the default when omitted. + + + useParensForNegativeNumbers: Optional. A vbTriState enumeration value specifying whether negative numbers should be encased in parenthesis. + + + vbTrue or -1: Use parenthesis for negative numbers. + + + vbFalse or 0: Do not display parenthesis. + + + vbUseDefaults or -2: Same as vbFalse. This is the default when omitted. + + + + groupDigits: Optional. A vbTriState enumeration value specifying the number should be grouped (into thousands, etc.), using the group delimiter that is specified on the system's regional settings. + + + + vbTrue or -1: Group digits. + + + vbFalse or 0: Do not group digits. + + + vbUseDefaults or -2: Same as vbFalse. This is the default when omitted. + + + + + + + Sub TestFormatNumeber + testName = "Test 1: positive, 2 decimals" + str2 = "12.20" + str1 = FormatNumber("12.2", 2, vbFalse, vbFalse, vbFalse) + msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2) + + testName = "Test 2: negative, 20 decimals, use leading zero" + str2 = "-0.20000000000000000000" + str1 = FormatNumber("-.2", 20, vbTrue, vbFalse, vbFalse) + msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2) + + testName = "Test 3: negative, 20 decimals, no leading zero" + str2 = "-.20000000000000000000" + str1 = FormatNumber("-0.2", 20, vbFalse, vbFalse, vbFalse) + msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2) + + testName = "Test 4: negative, no leading zero, use parens" + str2 = "(.20)" + str1 = FormatNumber("-0.2", -1, vbFalse, vbTrue, vbFalse) + msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2) + + testName = "Test 5: negative, default leading zero, use parens" + str2 = "(0.20)" + str1 = FormatNumber("-0.2", -1, vbUseDefault, vbTrue, vbFalse) + msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2) + + testName = "Test 6: group digits" + str2 = "-12,345,678.00" + str1 = FormatNumber("-12345678", -1, vbUseDefault, vbUseDefault, vbTrue) + msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2) + End Sub + +
+ +
+ +
diff --git a/source/text/sbasic/shared/special_vba_func.xhp b/source/text/sbasic/shared/special_vba_func.xhp index 003f3c5eb9..634891e7a8 100644 --- a/source/text/sbasic/shared/special_vba_func.xhp +++ b/source/text/sbasic/shared/special_vba_func.xhp @@ -92,12 +92,17 @@
+ + VBA Functions;Mathematical Functions + VBA Functions;formatting numbers Mathematical Functions + +
-- cgit