Difference between revisions of "G11ntest/Documentation/BASIC Guide/Arrays"
From Apache OpenOffice Wiki
(Created page with '{{文档//v2 | | |/Basic Guide/日期 |/Basic Guide/范围的变量 | }} {{DISPLAYTITLE:Arrays}} ____ 除了简单变量(标量)、 {{OOo}} Basic还支持阵列(数据字段…') |
|||
| Line 1: | Line 1: | ||
| − | {{ | + | {{Documentation/BASICGuideTOC/v2 |
| − | | | + | |ShowPrevNext=block |
| − | | | + | |ShowPrevPage=block |
| − | |/ | + | |PrevPage=Documentation/BASIC Guide/Date |
| − | |/ | + | |NextPage=Documentation/BASIC Guide/Scope of Variables |
| − | | | + | |lang=block |
}} | }} | ||
{{DISPLAYTITLE:Arrays}} | {{DISPLAYTITLE:Arrays}} | ||
| − | + | {{OOo}} | |
| − | |||
| − | = | + | == |
| − | |||
| + | ==== | ||
| − | |||
| − | |||
| − | |||
| − | |||
| + | <source lang="oobas"> | ||
| + | Dim MyArray(3) | ||
| + | </source> | ||
| − | |||
| + | <tt>MyArray(0)</tt><tt>MyArray(1)</tt><tt>MyArray(2)</tt><tt>MyArray(3)</tt> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | <source lang="oobas"> | |
| + | Dim MyInteger(3) As Integer | ||
| + | </source> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| + | <source lang="oobas"> | ||
| + | Dim MyInteger(5 To 10) As Integer | ||
| + | </source> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | <source lang="oobas"> | |
| + | Dim MyInteger(-10 To -5) As Integer | ||
| + | </source> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| + | <source lang="oobas"> | ||
| + | Dim s(-53000 to 89000) As String | ||
| + | s(-52000) = "aa" | ||
| + | s(79999) = "bb" | ||
| + | print s(-52000), s(79999) | ||
| + | </source> | ||
| − | |||
| + | {{Documentation/Note|}} | ||
| − | |||
| − | |||
| − | |||
| + | ==== | ||
| − | |||
| − | |||
| − | + | <source lang="oobas"> | |
| − | Option | + | Option Base 1 |
| + | </source> | ||
| + | |||
| + | |||
| + | {{OOo}} | ||
| + | |||
| + | |||
| + | <tt>Option Base 1</tt> | ||
| + | |||
| + | |||
| + | <source lang="oobas"> | ||
| + | Option Base 1 | ||
' ... | ' ... | ||
| − | Dim MyInteger(3) | + | Dim MyInteger(3) |
| − | </source> | + | </source> |
| + | |||
| + | <tt>MyInteger(1)</tt><tt>MyInteger(2)</tt><tt>MyInteger(3)</tt><tt>MyInteger(4)</tt> | ||
| − | |||
| + | {{Documentation/Note|{{OOo}}<tt>Option Base 1</tt>{{OOo}}<tt>MyInteger(3)</tt>{{OOo}}<tt>Option Compatible</tt>{{OOo}}}} | ||
| − | |||
| + | ==== | ||
| − | |||
| + | {{OOo}} | ||
| − | |||
| + | <source lang="oobas"> | ||
| + | Dim MyIntArray(5, 5) As Integer | ||
| + | </source> | ||
| − | |||
| − | |||
| − | |||
| + | = | ||
| − | |||
| + | {{OOo}} | ||
| − | |||
| + | ==== | ||
| − | |||
| + | {{OOo}} | ||
| − | |||
| + | <source lang="oobas"> | ||
| + | ReDim MyArray(10) | ||
| + | </source> | ||
| − | |||
| − | |||
| − | |||
| + | {{Documentation/Note|<tt>Dim MyArray()</tt>{{OOo}}<tt>ReDim</tt>}} | ||
| − | |||
| − | |||
| − | + | <source lang="oobas"> | |
| − | Dim MyArray(4) As Integer' | + | Dim MyArray(4) As Integer ' Declaration with five elements |
' ... | ' ... | ||
| − | ReDim MyArray(10)As Integer' | + | ReDim MyArray(10) As Integer ' Increase to 11 elements |
' ... | ' ... | ||
| − | ReDim MyArray(20)As Integer' | + | ReDim MyArray(20) As Integer ' Increase to 21 elements |
| − | </source> | + | </source> |
| − | + | <tt>Preserve</tt> | |
| − | + | <source lang="oobas"> | |
| − | Dim MyArray(10)As Integer' | + | Dim MyArray(10) As Integer ' Defining the initial |
| − | ' | + | ' dimensions |
' ... | ' ... | ||
| − | ReDim Preserve MyArray(20)As Integer' | + | ReDim Preserve MyArray(20) As Integer ' Increase in |
| − | " | + | ' data field, while |
| − | ' | + | ' retaining content |
| − | </source> | + | </source> |
| + | |||
| + | |||
| + | <tt>Preserve</tt> | ||
| + | |||
| + | |||
| + | {{Documentation/Note|<tt>Preserve</tt>{{OOo}}}} | ||
| + | |||
| + | |||
| + | <tt>ReDim</tt><tt>Preserve</tt> | ||
| + | |||
| + | |||
| + | ==== | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | <source lang="oobas"> | ||
| + | Dim MyArray(10) As Integer | ||
| + | ' ... some instructions | ||
| + | Dim n As Integer | ||
| + | n = 47 ' could be the result of a computation | ||
| + | Redim MyArray(n) As Integer | ||
| + | MsgBox(LBound(MyArray)) ' displays : 0 | ||
| + | MsgBox(UBound(MyArray)) ' displays : 47 | ||
| + | </source> | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | <source lang="oobas"> | ||
| + | Dim MyArray(10, 13 to 28) As Integer | ||
| + | MsgBox(LBound(MyArray, 2)) ' displays : 13 | ||
| + | MsgBox(UBound(MyArray, 2)) ' displays : 28 | ||
| + | </source> | ||
| + | |||
| + | |||
| + | ==== | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | <source lang="oobas"> | ||
| + | Dim s() As String ' declare an empty array | ||
| + | ' --- later in the program ... | ||
| + | Redim s(13) As String | ||
| + | </source> | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | <source lang="oobas"> | ||
| + | Dim MyArray() As Integer | ||
| + | MsgBox(LBound(MyArray)) ' displays : 0 | ||
| + | MsgBox(UBound(MyArray)) ' displays : -1 | ||
| + | </source> | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | == | ||
| − | |||
| − | |||
| + | = | ||
| − | |||
| + | == | ||
| − | |||
| − | |||
| − | |||
| − | |||
| + | == | ||
| − | |||
| − | |||
| − | = | + | = |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| Line 201: | Line 260: | ||
| − | {{InterWiki Languages BasicGuide|articletitle= | + | {{InterWiki Languages BasicGuide|articletitle=}} |
| + | {{PDL1}} | ||
| − | + | [[Category:G11n Wiki Translation]] | |
Revision as of 14:44, 21 October 2009
Apache OpenOffice
==
==
Dim MyArray(3)
MyArray(0)MyArray(1)MyArray(2)MyArray(3)
Dim MyInteger(3) As Integer
Dim MyInteger(5 To 10) As Integer
Dim MyInteger(-10 To -5) As Integer
Dim s(-53000 to 89000) As String
s(-52000) = "aa"
s(79999) = "bb"
print s(-52000), s(79999)
==
Option Base 1
Apache OpenOffice
Option Base 1
Option Base 1
' ...
Dim MyInteger(3)
MyInteger(1)MyInteger(2)MyInteger(3)MyInteger(4)
==
Apache OpenOffice
Dim MyIntArray(5, 5) As Integer
=
Apache OpenOffice
==
Apache OpenOffice
ReDim MyArray(10)
Dim MyArray(4) As Integer ' Declaration with five elements
' ...
ReDim MyArray(10) As Integer ' Increase to 11 elements
' ...
ReDim MyArray(20) As Integer ' Increase to 21 elements
Preserve
Dim MyArray(10) As Integer ' Defining the initial
' dimensions
' ...
ReDim Preserve MyArray(20) As Integer ' Increase in
' data field, while
' retaining content
Preserve
ReDimPreserve
==
Dim MyArray(10) As Integer
' ... some instructions
Dim n As Integer
n = 47 ' could be the result of a computation
Redim MyArray(n) As Integer
MsgBox(LBound(MyArray)) ' displays : 0
MsgBox(UBound(MyArray)) ' displays : 47
Dim MyArray(10, 13 to 28) As Integer
MsgBox(LBound(MyArray, 2)) ' displays : 13
MsgBox(UBound(MyArray, 2)) ' displays : 28
==
Dim s() As String ' declare an empty array
' --- later in the program ...
Redim s(13) As String
Dim MyArray() As Integer
MsgBox(LBound(MyArray)) ' displays : 0
MsgBox(UBound(MyArray)) ' displays : -1
==
=
==
==
=
| Content on this page is licensed under the Public Documentation License (PDL). |