summaryrefslogtreecommitdiffstats
path: root/source/text/sbasic/shared/03102100.xhp
diff options
context:
space:
mode:
authorLibreOfficiant <LibreOfficiant@sfr.fr>2020-04-20 15:22:22 +0100
committerOlivier Hallot <olivier.hallot@libreoffice.org>2020-04-23 17:35:19 +0200
commite2f2799a2808d4389cedab5f979a5a928d91d815 (patch)
treedf61e1f010e9c32b5b07665166d1df8b8f8755f3 /source/text/sbasic/shared/03102100.xhp
parenttdf#129366 Basic Byte datatype information (diff)
downloadhelp-e2f2799a2808d4389cedab5f979a5a928d91d815.tar.gz
help-e2f2799a2808d4389cedab5f979a5a928d91d815.zip
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 <olivier.hallot@libreoffice.org>
Diffstat (limited to 'source/text/sbasic/shared/03102100.xhp')
-rw-r--r--source/text/sbasic/shared/03102100.xhp150
1 files changed, 97 insertions, 53 deletions
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 @@
<body>
-
<section id="dimtext">
<bookmark xml-lang="en-US" branch="index" id="bm_id3149812">
<bookmark_value>Dim statement</bookmark_value>
@@ -35,73 +34,118 @@
<bookmark_value>dimensioning arrays</bookmark_value>
</bookmark>
-
-<paragraph id="hd_id3149812" role="heading" level="1" xml-lang="en-US"><link href="text/sbasic/shared/03102100.xhp" name="Dim Statement">Dim Statement</link></paragraph>
-<paragraph id="par_id3143271" role="paragraph" xml-lang="en-US">Declares a variable or an array.</paragraph>
+<h1 id="hd_id3149812" xml-lang="en-US"><link href="text/sbasic/shared/03102100.xhp" name="Dim Statement">Dim Statement</link></h1>
+<paragraph id="par_id3143271" role="paragraph">Declares variables or arrays.</paragraph>
</section>
-<paragraph id="par_id3154686" role="paragraph" xml-lang="en-US">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.</paragraph>
+
+<paragraph id="par_id3154686" role="paragraph" xml-lang="en-US">If the variables are separated by commas - for example <literal>Dim sPar1, sPar2, sPar3 As String</literal> - first ones get defined as Variant variables. A new line, or colon sign (<emph>:</emph>), help separate variable definitions.</paragraph>
<bascode>
-<paragraph id="par_idm871116272" role="bascode" localize="false" xml-lang="en-US">Dim sPar1 As String</paragraph>
-<paragraph id="par_idm871115040" role="bascode" localize="false" xml-lang="en-US">Dim sPar2 As String</paragraph>
-<paragraph id="par_idm871113808" role="bascode" localize="false" xml-lang="en-US">Dim sPar3 As String</paragraph>
+ <paragraph id="par_idm871116272" role="bascode" localize="false">Dim sPar1 As String</paragraph>
+ <paragraph id="par_idm871115040" role="bascode" localize="false">Dim sPar2 As String, SPar3 As String</paragraph>
+ <paragraph role="bascode" id="bas_id591587474364949" localize="false">Dim Units as Integer : Dim EULER As Double</paragraph>
</bascode>
-<paragraph id="par_id3152576" role="paragraph" xml-lang="en-US">Dim declares local variables within subroutines. Global variables are declared with the PUBLIC or the PRIVATE statement.</paragraph>
+<paragraph id="par_id3152576" role="paragraph" xml-lang="en-US"><literal>Dim</literal> declares local variables within subroutines. Global variables are declared with the <literal>Global</literal>, <literal>Public</literal> or the <literal>Private</literal> statement.</paragraph>
-<paragraph id="hd_id3156443" role="heading" level="2" xml-lang="en-US">Syntax:</paragraph>
+<embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
+<paragraph role="paragraph" id="par_id971587473488701">
+ <image src="media/helpimg/sbasic/Dim_statement.svg" id="img_id4156296484514"><alt xml-lang="en-US" id="alt_id15152796484514">Dim Statement diagram</alt></image>
+</paragraph>
<bascode>
-<paragraph id="par_id3149412" role="bascode" xml-lang="en-US">[ReDim]Dim VarName [(start To end)] [As VarType][, VarName2 [(start To end)] [As VarType][,...]]</paragraph>
+<paragraph id="par_id3149412" role="bascode" xml-lang="en-US">Dim variable [(start To end)] [As type-name][, variable2[type-char] [(start To end)] [,...]]</paragraph>
</bascode>
-<paragraph id="hd_id3147397" role="heading" level="2" xml-lang="en-US">Parameters:</paragraph>
-<paragraph id="par_id3154730" role="paragraph" xml-lang="en-US"> <emph>VarName:</emph> Any variable or array name.</paragraph>
-<paragraph id="par_id3147125" role="paragraph" xml-lang="en-US"> <emph>Start, End:</emph> Numerical values or constants that define the number of elements (NumberElements=(end-start)+1) and the index range.<comment>see #i36558</comment></paragraph>
-<paragraph id="par_id3153877" role="paragraph" xml-lang="en-US">Start and End can be numerical expressions if ReDim is applied at the procedure level.</paragraph>
-<paragraph id="par_id3153510" role="paragraph" xml-lang="en-US"> <emph>VarType:</emph> Key word that declares the data type of a variable.</paragraph>
-<paragraph id="par_id3154015" role="paragraph" xml-lang="en-US"> <emph>Keyword:</emph> Variable type</paragraph>
-<paragraph id="par_id3153949" role="paragraph" xml-lang="en-US"> <emph>Bool:</emph> Boolean variable (True, False)</paragraph>
-<paragraph id="par_id3156275" role="paragraph" xml-lang="en-US"> <emph>Currency:</emph> Currency-Variable (Currency with 4 Decimal places)</paragraph>
+<section id="DimCommons">
+<embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
+<paragraph id="par_id3154730" role="paragraph" xml-lang="en-US"> <emph>variable:</emph> Any variable or array name.</paragraph>
+<paragraph id="par_id3147125" role="paragraph" xml-lang="en-US"> <emph>start, end:</emph> Numerical values or constants that define the number of elements (NumberElements=(end-start)+1) and the index range.<comment>see #i36558</comment></paragraph>
+<paragraph id="par_id3153877" role="paragraph" xml-lang="en-US"> <emph>start</emph> and <emph>end</emph> can be numerical expressions if <literal>ReDim</literal> is applied at the procedure level.</paragraph>
+
+<paragraph id="par_id3154510" role="paragraph" xml-lang="en-US"> <emph>type-name:</emph> Keyword that declares the data type of a variable.</paragraph>
+<paragraph role="paragraph" id="par_id971587473508701">
+ <image src="media/helpimg/sbasic/type-name_fragment.svg" id="img_id4156296484515"><alt xml-lang="en-US" id="alt_id15152796484515">primitive data types fragment</alt></image>
+</paragraph>
+<paragraph role="paragraph" id="par_id21587557790810"> <emph>Byte:</emph> Byte variable (0-255)</paragraph>
+<paragraph id="par_id3153949" role="paragraph" xml-lang="en-US"> <emph>Boolean:</emph> Boolean variable (True, False)</paragraph>
+<paragraph id="par_id3156275" role="paragraph" xml-lang="en-US"> <emph>Currency:</emph> Currency variable (Currency with 4 Decimal places)</paragraph>
<paragraph id="par_id3156057" role="paragraph" xml-lang="en-US"> <emph>Date:</emph> Date variable</paragraph>
-<paragraph id="par_id3148405" role="paragraph" xml-lang="en-US"> <emph>Double:</emph> Double-precision floating-point variable (1,79769313486232 x 10E308 - 4,94065645841247 x 10E-324)</paragraph>
+<paragraph id="par_id3148405" role="paragraph" xml-lang="en-US"> <emph>Double:</emph> Double-precision floating-point variable (1,79769313486232 x 10E308 - 4,94065645841247 x 10E-324)</paragraph>
<paragraph id="par_id3148916" role="paragraph" xml-lang="en-US"> <emph>Integer:</emph> Integer variable (-32768 - 32767)</paragraph>
<paragraph id="par_id3150045" role="paragraph" xml-lang="en-US"> <emph>Long:</emph> Long integer variable (-2.147.483.648 - 2.147.483.647)</paragraph>
-<paragraph id="par_id3149255" role="paragraph" xml-lang="en-US"> <emph>Object:</emph> Object variable (Note: this variable can only subsequently be defined with Set!)</paragraph>
+<paragraph id="par_id3149255" role="paragraph" xml-lang="en-US"> <emph>Object:</emph> Object variable (Note: this variable can only subsequently be defined with <literal>Set</literal>!)</paragraph>
<paragraph id="par_id3155937" role="paragraph" xml-lang="en-US"> <emph>Single:</emph> Single-precision floating-point variable (3,402823 x 10E38 - 1,401298 x 10E-45).</paragraph>
<paragraph id="par_id3151251" role="paragraph" xml-lang="en-US"> <emph>String:</emph> String variable consisting of a maximum of 64,000 ASCII characters.</paragraph>
-<paragraph id="par_id3154704" role="paragraph" xml-lang="en-US"> <emph>[Variant]:</emph> 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.</paragraph>
-<paragraph id="par_id3146316" role="paragraph" xml-lang="en-US">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.</paragraph>
+<paragraph id="par_id3154704" role="paragraph" xml-lang="en-US"> <emph>Variant:</emph> 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 <literal>DefBool</literal> to <literal>DefVar</literal> is used.</paragraph>
+<paragraph id="par_id3153510" role="paragraph" xml-lang="en-US"><emph>type-char:</emph> Special character that declares the data type of a variable.</paragraph><paragraph role="paragraph" id="par_id971587473518701">
+ <image src="media/helpimg/sbasic/type-car_fragment.svg" id="img_id4156296484516"><alt xml-lang="en-US" id="alt_id15152796484516">Type declaration characters fragment</alt></image>
+</paragraph>
+<paragraph id="par_id3146316" role="paragraph" xml-lang="en-US">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 <literal>Dim</literal> statement, using commas (<emph>,</emph>) to separate multiple declarations. To declare a variable type, enter a type-declaration character following the name or use a corresponding type keyword name.</paragraph>
+<table id="tab_id821587558178871">
+ <tablerow>
+ <tablecell><paragraph id="par_id411587558178871" role="tablehead">Declaration character</paragraph></tablecell>
+ <tablecell><paragraph id="par_id851587558178871" role="tablehead">Variable type name</paragraph></tablecell>
+ </tablerow>
+ <tablerow>
+ <tablecell><paragraph id="par_id211587558178871" role="tablecontent">%</paragraph></tablecell>
+ <tablecell><paragraph id="par_id42587558178871" role="tablecontent">Integer</paragraph></tablecell>
+ </tablerow>
+ <tablerow>
+ <tablecell><paragraph id="par_id221587558178871" role="tablecontent">&amp;</paragraph></tablecell>
+ <tablecell><paragraph id="par_id43587558178871" role="tablecontent">Long</paragraph></tablecell>
+ </tablerow>
+ <tablerow>
+ <tablecell><paragraph id="par_id231587558178871" role="tablecontent">!</paragraph></tablecell>
+ <tablecell><paragraph id="par_id44587558178871" role="tablecontent">Single</paragraph></tablecell>
+ </tablerow>
+ <tablerow>
+ <tablecell><paragraph id="par_id241587558178871" role="tablecontent">#</paragraph></tablecell>
+ <tablecell><paragraph id="par_id45587558178871" role="tablecontent">Double</paragraph></tablecell>
+ </tablerow>
+ <tablerow>
+ <tablecell><paragraph id="par_id251587558178871" role="tablecontent">$</paragraph></tablecell>
+ <tablecell><paragraph id="par_id46587558178871" role="tablecontent">String</paragraph></tablecell>
+ </tablerow>
+</table>
+
+<paragraph role="paragraph" id="par_id441587477911298"> <emph>array:</emph> Array declaration.</paragraph>
+<paragraph role="paragraph" id="par_id971587473519701">
+ <image src="media/helpimg/sbasic/array_fragment.svg" id="img_id4156296485516"><alt xml-lang="en-US" id="alt_id15152796485516">array fragment</alt></image>
+</paragraph>
<paragraph id="par_id3149924" role="paragraph" xml-lang="en-US">$[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.</paragraph>
-<paragraph id="par_id3148488" role="paragraph" xml-lang="en-US">Arrays are declared with the Dim statement. There are two methods to define the index range:</paragraph>
-<paragraph id="par_id3154662" role="paragraph" xml-lang="en-US">DIM text(20) as String REM 21 elements numbered from 0 to 20</paragraph>
-<paragraph id="par_id3155604" role="paragraph" xml-lang="en-US">DIM text(5 to 25) as String REM 21 elements numbered from 5 to 25</paragraph>
-<paragraph id="par_id3151274" role="paragraph" xml-lang="en-US">DIM text(-15 to 5) as String REM 21 elements (including 0)</paragraph>
-<paragraph id="par_id3152774" role="paragraph" xml-lang="en-US">REM numbered from -15 to 5</paragraph>
-<paragraph id="par_id3150829" role="paragraph" xml-lang="en-US">Two-dimensional data field</paragraph>
-<paragraph id="par_id3149529" role="paragraph" xml-lang="en-US">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.</paragraph>
-<paragraph id="par_id3159239" role="paragraph" xml-lang="en-US">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.</paragraph>
+ <paragraph id="par_id3148488" role="paragraph" xml-lang="en-US">Arrays are declared with the <literal>Dim</literal> statement. There are multiple ways to define the index range:</paragraph>
+<bascode>
+ <paragraph role="bascode" id="bas_id381587475057846" xml-lang="en-US">Dim text(20) As String ' 21 elements numbered from 0 to 20</paragraph>
+ <paragraph role="bascode" id="bas_id1001587475058292" xml-lang="en-US">Dim value(5 to 25) As Integer ' 21 values numbered from 5 to 25</paragraph>
+ <paragraph role="bascode" id="bas_id481587475059423" xml-lang="en-US">Dim amount(-15 to 5) As Currency ' 21 amounts (including 0), numbered from -15 to 5</paragraph>
+ <paragraph role="bascode" id="bas_id621587475059824" xml-lang="en-US">REM Two-dimensional data field</paragraph>
+ <paragraph role="bascode" id="bas_id11587475060830" xml-lang="en-US">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.</paragraph>
+</bascode>
+
+<paragraph id="par_id3159239" role="paragraph" xml-lang="en-US">You can declare an array types as dynamic if a <literal>ReDim</literal> 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 <literal>ReDim</literal>. You can only define dimensions with numeric expressions. This ensures that the fields are only as large as necessary.</paragraph>
+</section>
-<paragraph id="hd_id3150344" role="heading" level="2" xml-lang="en-US">Example:</paragraph>
+<embed href="text/sbasic/shared/00000003.xhp#functexample"/>
<bascode>
-<paragraph id="par_idm871051008" role="bascode" localize="false" xml-lang="en-US">Sub ExampleDim1</paragraph>
-<paragraph id="par_idm871049776" role="bascode" localize="false" xml-lang="en-US">Dim sVar As String</paragraph>
-<paragraph id="par_idm871048544" role="bascode" localize="false" xml-lang="en-US">Dim iVar As Integer</paragraph>
-<paragraph id="par_id3154657" role="bascode" xml-lang="en-US"> sVar = "Office"</paragraph>
-<paragraph id="par_idm871045600" role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph>
-<paragraph id="par_idm871044368" role="bascode" localize="false" xml-lang="en-US"> </paragraph>
-<paragraph id="par_idm871043120" role="bascode" localize="false" xml-lang="en-US">Sub ExampleDim2</paragraph>
-<paragraph id="par_id3149036" role="bascode" xml-lang="en-US">' Two-dimensional data field</paragraph>
-<paragraph id="par_idm871040112" role="bascode" localize="false" xml-lang="en-US">Dim stext(20,2) As String</paragraph>
-<paragraph id="par_id3153782" role="bascode" xml-lang="en-US">Const sDim As String = " Dimension:"</paragraph>
-<paragraph id="par_idm871037136" role="bascode" localize="false" xml-lang="en-US">For i = 0 To 20</paragraph>
-<paragraph id="par_idm871035904" role="bascode" localize="false" xml-lang="en-US"> For ii = 0 To 2</paragraph>
-<paragraph id="par_idm871034672" role="bascode" localize="false" xml-lang="en-US"> stext(i,ii) = str(i) &amp; sDim &amp; str(ii)</paragraph>
-<paragraph id="par_idm871033392" role="bascode" localize="false" xml-lang="en-US"> Next ii</paragraph>
-<paragraph id="par_idm871032160" role="bascode" localize="false" xml-lang="en-US">Next i</paragraph>
-<paragraph id="par_idm871030928" role="bascode" localize="false" xml-lang="en-US">For i = 0 To 20</paragraph>
-<paragraph id="par_idm871029696" role="bascode" localize="false" xml-lang="en-US"> For ii = 0 To 2</paragraph>
-<paragraph id="par_idm871028464" role="bascode" localize="false" xml-lang="en-US"> MsgBox stext(i,ii)</paragraph>
-<paragraph id="par_idm871027216" role="bascode" localize="false" xml-lang="en-US"> Next ii</paragraph>
-<paragraph id="par_idm871025984" role="bascode" localize="false" xml-lang="en-US">Next i</paragraph>
-<paragraph id="par_idm871024752" role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph>
+<paragraph id="par_idm871051008" role="bascode" localize="false">Sub ExampleDim1</paragraph>
+<paragraph id="par_idm871049776" role="bascode" localize="false">Dim sVar As String</paragraph>
+<paragraph id="par_idm871048544" role="bascode" localize="false">Dim iVar As Integer</paragraph>
+<paragraph id="par_id3154657" role="bascode" localize="false"> sVar = "Office"</paragraph>
+<paragraph id="par_idm871045600" role="bascode" localize="false">End Sub</paragraph>
+<paragraph id="par_idm871044368" role="bascode" localize="false"> </paragraph>
+<paragraph id="par_idm871043120" role="bascode" localize="false">Sub ExampleDim2</paragraph>
+<paragraph id="par_id3149036" role="bascode" xml-lang="en-US"> ' Two-dimensional data field</paragraph>
+<paragraph id="par_idm871040112" role="bascode" localize="false"> Dim stext(20,2) As String</paragraph>
+<paragraph id="par_id3153782" role="bascode" xml-lang="en-US"> Const sDim As String = " Dimension:"</paragraph>
+<paragraph id="par_idm871037136" role="bascode" localize="false"> For i = 0 To 20</paragraph>
+<paragraph id="par_idm871035904" role="bascode" localize="false"> For ii = 0 To 2</paragraph>
+<paragraph id="par_idm871034672" role="bascode" localize="false"> stext(i,ii) = str(i) &amp; sDim &amp; str(ii)</paragraph>
+<paragraph id="par_idm871033392" role="bascode" localize="false"> Next ii</paragraph>
+<paragraph id="par_idm871032160" role="bascode" localize="false"> Next i</paragraph>
+<paragraph id="par_idm871030928" role="bascode" localize="false"> For i = 0 To 20</paragraph>
+<paragraph id="par_idm871029696" role="bascode" localize="false"> For ii = 0 To 2</paragraph>
+<paragraph id="par_idm871028464" role="bascode" localize="false"> MsgBox stext(i,ii)</paragraph>
+<paragraph id="par_idm871027216" role="bascode" localize="false"> Next ii</paragraph>
+<paragraph id="par_idm871025984" role="bascode" localize="false"> Next i</paragraph>
+<paragraph id="par_idm871024752" role="bascode" localize="false">End Sub</paragraph>
</bascode>
</body>