From e2f2799a2808d4389cedab5f979a5a928d91d815 Mon Sep 17 00:00:00 2001 From: LibreOfficiant Date: Mon, 20 Apr 2020 15:22:22 +0100 Subject: tdf#129366 Basic Syntax Diagrams - runtime/compiler Option statements - Sub, Function, Property Get/Let/Set - Dim, ReDim, DimArray - Dim and Redim help pages reviewed and amended accordingly - Sub, Function, Property pages updates in subsequent patches Change-Id: Iee857aa6e17533278bf16917c0b7d32af0e038ea Reviewed-on: https://gerrit.libreoffice.org/c/help/+/92528 Tested-by: Jenkins Reviewed-by: Olivier Hallot --- Package_html_media.mk | 8 ++ source/media/helpimg/sbasic/DimArray_function.svg | 45 +++++++ source/media/helpimg/sbasic/Dim_statement.svg | 54 ++++++++ source/media/helpimg/sbasic/Function_statement.svg | 58 ++++++++ source/media/helpimg/sbasic/Option_statement.svg | 45 +++++++ .../helpimg/sbasic/Property-Get_statement.svg | 48 +++++++ .../helpimg/sbasic/Property-Set_statement.svg | 48 +++++++ source/media/helpimg/sbasic/ReDim_statement.svg | 54 ++++++++ source/media/helpimg/sbasic/Sub_statement.svg | 52 +++++++ source/text/sbasic/shared/03102100.xhp | 150 +++++++++++++-------- source/text/sbasic/shared/03102101.xhp | 60 +++------ 11 files changed, 529 insertions(+), 93 deletions(-) create mode 100644 source/media/helpimg/sbasic/DimArray_function.svg create mode 100644 source/media/helpimg/sbasic/Dim_statement.svg create mode 100644 source/media/helpimg/sbasic/Function_statement.svg create mode 100644 source/media/helpimg/sbasic/Option_statement.svg create mode 100644 source/media/helpimg/sbasic/Property-Get_statement.svg create mode 100644 source/media/helpimg/sbasic/Property-Set_statement.svg create mode 100644 source/media/helpimg/sbasic/ReDim_statement.svg create mode 100644 source/media/helpimg/sbasic/Sub_statement.svg diff --git a/Package_html_media.mk b/Package_html_media.mk index f663095e17..b1a95ec289 100644 --- a/Package_html_media.mk +++ b/Package_html_media.mk @@ -112,11 +112,19 @@ $(eval $(call gb_Package_add_files_with_dir,helpcontent2_html_media,$(LIBO_SHARE helpimg/sbasic/type-car_fragment.svg \ helpimg/sbasic/type-name_fragment.svg \ helpimg/sbasic/Call_statement.svg \ + helpimg/sbasic/Dim_statement.svg \ + helpimg/sbasic/DimArray_function.svg \ helpimg/sbasic/For-Each_statement.svg \ helpimg/sbasic/For-Next_statement.svg \ + helpimg/sbasic/Function_statement.svg \ helpimg/sbasic/LetSet_statement.svg \ helpimg/sbasic/On-Error_statement.svg \ + helpimg/sbasic/Option_statement.svg \ + helpimg/sbasic/Property-Get_statement.svg \ + helpimg/sbasic/Property-Set_statement.svg \ + helpimg/sbasic/ReDim_statement.svg \ helpimg/sbasic/Resume_statement.svg \ + helpimg/sbasic/Sub_statement.svg \ helpimg/sbasic/Type_statement.svg \ helpimg/scalc/coordinates-to-polar-01.svg \ helpimg/starmath/harpoon.svg \ diff --git a/source/media/helpimg/sbasic/DimArray_function.svg b/source/media/helpimg/sbasic/DimArray_function.svg new file mode 100644 index 0000000000..327c16176a --- /dev/null +++ b/source/media/helpimg/sbasic/DimArray_function.svg @@ -0,0 +1,45 @@ + + + + + + + + +variable += +DimArray +( + + + +upper_bound +, +) \ No newline at end of file diff --git a/source/media/helpimg/sbasic/Dim_statement.svg b/source/media/helpimg/sbasic/Dim_statement.svg new file mode 100644 index 0000000000..f2d06e0b27 --- /dev/null +++ b/source/media/helpimg/sbasic/Dim_statement.svg @@ -0,0 +1,54 @@ + + + + + +Dim +Global +Private +Public +Static + + +variable + + + + +array + +As +type-name + +type-car + + +array +, \ No newline at end of file diff --git a/source/media/helpimg/sbasic/Function_statement.svg b/source/media/helpimg/sbasic/Function_statement.svg new file mode 100644 index 0000000000..f3c0c7a2b5 --- /dev/null +++ b/source/media/helpimg/sbasic/Function_statement.svg @@ -0,0 +1,58 @@ + + + + + + + + +Global +Public +Private +Function +name + + +type-car +( + +argument +, +) + +( + +argument +, +) +As +type-name +statements +End Function \ No newline at end of file diff --git a/source/media/helpimg/sbasic/Option_statement.svg b/source/media/helpimg/sbasic/Option_statement.svg new file mode 100644 index 0000000000..0ef3391cc6 --- /dev/null +++ b/source/media/helpimg/sbasic/Option_statement.svg @@ -0,0 +1,45 @@ + + + + + +Option + + + +Base +VBASupport + +0 +1 +ClassModule +Compatible +Explicit +Private Module \ No newline at end of file diff --git a/source/media/helpimg/sbasic/Property-Get_statement.svg b/source/media/helpimg/sbasic/Property-Get_statement.svg new file mode 100644 index 0000000000..6671ed85ed --- /dev/null +++ b/source/media/helpimg/sbasic/Property-Get_statement.svg @@ -0,0 +1,48 @@ + + + + + + + + +Global +Public +Private +Property Get +name + + +type-car + +As +type-name +statements +End Property \ No newline at end of file diff --git a/source/media/helpimg/sbasic/Property-Set_statement.svg b/source/media/helpimg/sbasic/Property-Set_statement.svg new file mode 100644 index 0000000000..51235b1748 --- /dev/null +++ b/source/media/helpimg/sbasic/Property-Set_statement.svg @@ -0,0 +1,48 @@ + + + + + + + + +Global +Public +Private +Property + +Let +Set +name +( +argument +) +statements +End Property \ No newline at end of file diff --git a/source/media/helpimg/sbasic/ReDim_statement.svg b/source/media/helpimg/sbasic/ReDim_statement.svg new file mode 100644 index 0000000000..5f26deaef6 --- /dev/null +++ b/source/media/helpimg/sbasic/ReDim_statement.svg @@ -0,0 +1,54 @@ + + + + +ReDim + + +Preserve + + + + +variable + + + + +array + +As +type-name + +type-car + + +array +, \ No newline at end of file diff --git a/source/media/helpimg/sbasic/Sub_statement.svg b/source/media/helpimg/sbasic/Sub_statement.svg new file mode 100644 index 0000000000..f1e46ae8d2 --- /dev/null +++ b/source/media/helpimg/sbasic/Sub_statement.svg @@ -0,0 +1,52 @@ + + + + + + + + +Global +Public +Private +Sub +name + + + +( + + + +argument +, +) +statements +End Sub \ No newline at end of file diff --git a/source/text/sbasic/shared/03102100.xhp b/source/text/sbasic/shared/03102100.xhp index af326b4c19..e6f9f49b17 100644 --- a/source/text/sbasic/shared/03102100.xhp +++ b/source/text/sbasic/shared/03102100.xhp @@ -27,7 +27,6 @@ -
Dim statement @@ -35,73 +34,118 @@ dimensioning arrays - -Dim Statement -Declares a variable or an array. +

Dim Statement

+Declares variables or arrays.
-If the variables are separated by commas (for example, DIM sPar1, sPar2, sPar3 AS STRING), only Variant variables can be defined. Use a separate definition line for each variable. + +If the variables are separated by commas - for example Dim sPar1, sPar2, sPar3 As String - first ones get defined as Variant variables. A new line, or colon sign (:), help separate variable definitions. -Dim sPar1 As String -Dim sPar2 As String -Dim sPar3 As String + Dim sPar1 As String + Dim sPar2 As String, SPar3 As String + Dim Units as Integer : Dim EULER As Double -Dim declares local variables within subroutines. Global variables are declared with the PUBLIC or the PRIVATE statement. +Dim declares local variables within subroutines. Global variables are declared with the Global, Public or the Private statement. -Syntax: + + + Dim Statement diagram + -[ReDim]Dim VarName [(start To end)] [As VarType][, VarName2 [(start To end)] [As VarType][,...]] +Dim variable [(start To end)] [As type-name][, variable2[type-char] [(start To end)] [,...]] -Parameters: - VarName: Any variable or array name. - Start, End: Numerical values or constants that define the number of elements (NumberElements=(end-start)+1) and the index range.see #i36558 -Start and End can be numerical expressions if ReDim is applied at the procedure level. - VarType: Key word that declares the data type of a variable. - Keyword: Variable type - Bool: Boolean variable (True, False) - Currency: Currency-Variable (Currency with 4 Decimal places) +
+ + variable: Any variable or array name. + start, end: Numerical values or constants that define the number of elements (NumberElements=(end-start)+1) and the index range.see #i36558 + start and end can be numerical expressions if ReDim is applied at the procedure level. + + type-name: Keyword that declares the data type of a variable. + + primitive data types fragment + + Byte: Byte variable (0-255) + Boolean: Boolean variable (True, False) + Currency: Currency variable (Currency with 4 Decimal places) Date: Date variable - Double: Double-precision floating-point variable (1,79769313486232 x 10E308 - 4,94065645841247 x 10E-324) + Double: Double-precision floating-point variable (1,79769313486232 x 10E308 - 4,94065645841247 x 10E-324) Integer: Integer variable (-32768 - 32767) Long: Long integer variable (-2.147.483.648 - 2.147.483.647) - Object: Object variable (Note: this variable can only subsequently be defined with Set!) + Object: Object variable (Note: this variable can only subsequently be defined with Set!) Single: Single-precision floating-point variable (3,402823 x 10E38 - 1,401298 x 10E-45). String: String variable consisting of a maximum of 64,000 ASCII characters. - [Variant]: Variant variable type (contains all types, specified by definition). If a key word is not specified, variables are automatically defined as Variant Type, unless a statement from DefBool to DefVar is used. -In $[officename] Basic, you do not need to declare variables explicitly. However, you need to declare an array before you can use them. You can declare a variable with the Dim statement, using commas to separate multiple declarations. To declare a variable type, enter a type-declaration character following the name or use a corresponding key word. + Variant: Variant variable type (contains all types, specified by definition). If a type name is not specified, variables are automatically defined as Variant Type, unless a statement from DefBool to DefVar is used. +type-char: Special character that declares the data type of a variable. + Type declaration characters fragment + +In %PRODUCTNAME Basic, you do not need to declare variables explicitly. However, you need to declare arrays before you can use them. You can declare a variable with the Dim statement, using commas (,) to separate multiple declarations. To declare a variable type, enter a type-declaration character following the name or use a corresponding type keyword name. + + + Declaration character + Variable type name + + + % + Integer + + + & + Long + + + ! + Single + + + # + Double + + + $ + String + +
+ + array: Array declaration. + + array fragment + $[officename] Basic supports single or multi-dimensional arrays that are defined by a specified variable type. Arrays are suitable if the program contains lists or tables that you want to edit. The advantage of arrays is that it is possible to address individual elements according to indexes, which can be formulated as numeric expressions or variables. -Arrays are declared with the Dim statement. There are two methods to define the index range: -DIM text(20) as String REM 21 elements numbered from 0 to 20 -DIM text(5 to 25) as String REM 21 elements numbered from 5 to 25 -DIM text(-15 to 5) as String REM 21 elements (including 0) -REM numbered from -15 to 5 -Two-dimensional data field -DIM text(20,2) as String REM 63 elements; form 0 to 20 level 1, from 0 to 20 level 2 and from 0 to 20 level 3. -You can declare an array types as dynamic if a ReDim statement defines the number of dimensions in the subroutine or the function that contains the array. Generally, you can only define an array dimension once, and you cannot modify it. Within a subroutine, you can declare an array with ReDim. You can only define dimensions with numeric expressions. This ensures that the fields are only as large as necessary. + Arrays are declared with the Dim statement. There are multiple ways to define the index range: + + Dim text(20) As String ' 21 elements numbered from 0 to 20 + Dim value(5 to 25) As Integer ' 21 values numbered from 5 to 25 + Dim amount(-15 to 5) As Currency ' 21 amounts (including 0), numbered from -15 to 5 + REM Two-dimensional data field + Dim table$(20,2) ' 63 items; from 0 to 20 level 1, from 0 to 20 level 2 and from 0 to 20 level 3. + + +You can declare an array types as dynamic if a ReDim statement defines the number of dimensions in the subroutine or the function that contains the array. Generally, you can only define an array dimension once, and you cannot modify it. Within a subroutine, you can declare an array with ReDim. You can only define dimensions with numeric expressions. This ensures that the fields are only as large as necessary. +
-Example: + -Sub ExampleDim1 -Dim sVar As String -Dim iVar As Integer - sVar = "Office" -End Sub - -Sub ExampleDim2 -' Two-dimensional data field -Dim stext(20,2) As String -Const sDim As String = " Dimension:" -For i = 0 To 20 - For ii = 0 To 2 - stext(i,ii) = str(i) & sDim & str(ii) - Next ii -Next i -For i = 0 To 20 - For ii = 0 To 2 - MsgBox stext(i,ii) - Next ii -Next i -End Sub +Sub ExampleDim1 +Dim sVar As String +Dim iVar As Integer + sVar = "Office" +End Sub + +Sub ExampleDim2 + ' Two-dimensional data field + Dim stext(20,2) As String + Const sDim As String = " Dimension:" + For i = 0 To 20 + For ii = 0 To 2 + stext(i,ii) = str(i) & sDim & str(ii) + Next ii + Next i + For i = 0 To 20 + For ii = 0 To 2 + MsgBox stext(i,ii) + Next ii + Next i +End Sub diff --git a/source/text/sbasic/shared/03102101.xhp b/source/text/sbasic/shared/03102101.xhp index 6d00c0226d..8c71168a43 100644 --- a/source/text/sbasic/shared/03102101.xhp +++ b/source/text/sbasic/shared/03102101.xhp @@ -33,54 +33,34 @@ ReDim statement - -ReDim Statement -Declares a variable or an array. +

ReDim Statement

+Declares or redefines variables or arrays. -Syntax: + + + ReDim Statement diagram + -[ReDim]Dim VarName [(start To end)] [As VarType][, VarName2 [(start To end)] [As VarType][,...]] +ReDim [Preserve] variable [(start To end)] [As type-name][, variable2 [(start To end)] [As type-name][,...]] -Optionally, you can add the Preserve keyword as a parameter to preserve the contents of the array that is redimensioned. +Optionally, add the Preserve keyword to preserve the contents of the array that is redimensioned. ReDim can only be used in subroutines. -Parameters: - VarName: Any variable or array name. - Start, End: Numerical values or constants that define the number of elements (NumberElements=(end-start)+1) and the index range. -Start and End can be numeric expressions if ReDim is used at the procedure level. - VarType: Keyword that declares the data type of a variable. - Keyword: Variable type - Bool: Boolean variable (True, False) - Date: Date variable - Double: Double floating point variable (1.79769313486232x10E308 - 4.94065645841247x10E-324) - Integer: Integer variable (-32768 - 32767) - Long: Long integer variable (-2,147,483,648 - 2,147,483,647) - Object: Object variable (can only be subsequently defined by Set!) - [Single]: Single floating-point variable (3.402823x10E38 - 1.401298x10E-45). If no key word is specified, a variable is defined as Single, unless a statement from DefBool to DefVar is used. - String: String variable containing a maximum of 64,000 ASCII characters. - Variant: Variant variable type (can contain all types and is set by definition). -In $[officename] Basic, you do not need to declare variables explicitly. However, you need to declare an array before you can use them. You can declare a variable with the Dim statement, using commas to separate multiple declarations. To declare a variable type, enter a type-declaration character following the name or use a corresponding key word. -$[officename] Basic supports single or multi-dimensional arrays that are defined by a specified variable type. Arrays are suitable if the program contains lists or tables that you want to edit. The advantage of arrays is that it is possible to address individual elements according to indexes, which can be formulated as numeric expressions or variables. -There are two ways to set the range of indices for arrays declared with the Dim statement: -DIM text(20) As String REM 21 elements numbered from 0 to 20 -DIM text(5 to 25) As String REM 21 elements numbered from 5 to 25 -DIM text$(-15 to 5) As String REM 21 elements (0 inclusive), -rem numbered from -15 to 5 -Variable fields, regardless of type, can be made dynamic if they are dimensioned by ReDim at the procedure level in subroutines or functions. Normally, you can only set the range of an array once and you cannot modify it. Within a procedure, you can declare an array using the ReDim statement with numeric expressions to define the range of the field sizes. + Example: -Sub ExampleRedim -Dim iVar() As Integer, iCount As Integer -ReDim iVar(5) As Integer -For iCount = 1 To 5 - iVar(iCount) = iCount -Next iCount -ReDim iVar(10) As Integer -For iCount = 1 To 10 - iVar(iCount) = iCount -Next iCount -End Sub +Sub ExampleRedim + Dim iVar() As Integer, iCount As Byte + ReDim iVar(5) As Integer + For iCount = 1 To 5 + iVar(iCount) = iCount + Next iCount + ReDim iVar(10) As Integer + For iCount = 1 To 10 + iVar(iCount) = iCount + Next iCount +End Sub -- cgit