Jump to content

User:LibreOfficiant/BasicSyntax

From The Document Foundation Wiki

Basic syntax source files are part of NextCloud documentation

How to Read Diagrams

Compiler options: As well as Runtime options …
a statement diagram: Separate statements with new line or colon sign (:).
comment fragment: To prefix with REM or an apostrophe sign.
typename: Primitive data type names
char: Type declaration characters
array fragment: Multiple optional dimensions, optional start lower bound, end upper bound.
Diagrams Notations
  • Propercasing denotes LibreOffice Basic keywords: Call, DimArray, InputBox, Property, …
  • lowercase characters indicate information to supply: end, expression, start, variable, …
  • Basic statement diagrams start and end with double vertical bars,
  • Loops indicate a possible repetition, an optional separator may be present,
  • Rectangles denote subsequent diagram fragments,
  • Diagram fragments extremities exhibit single vertical bars.
  • [opt1|opt2|opt3] Items inside brackets are optional. Alternatives are indicated with a vertical bar,
  • case[[sep]…] An ellipsis indicates a possible repetition. An optional separator may be specified,
  • {choice1|choice2} Items inside curly braces are mandatory. Alternatives are indicated with a vertical bar.

Examples

A statement diagram: Let, New and Set are Basic keywords, expression, object and variable are arguments
Let or Set are optional default statements. New creates UNO objects or ClassModule objects.

Misc.

Beep statement.
Stop statement.
With statement.

Data Types, Constants & Variables

Constants



Variable declarations: Dim, ReDim statements




Variable Assignments: Let/Set statements

Let or Set statements …


Data type conversions

Arrays: Array, DimArray functions, Erase statement




Scope of declarations: Accessers

Booleans values

Date/Time

Variants

Collections

Expressions & Operators

Managing Flow of Control

Testing conditions: Do, If, Select Case, While statements



IfThenElse statement: …


Select CaseEnd Select statement: …



Iterating: For statement

For=ToNext statement: …


statements: Separate statements with new line or colon sign (:).
For EachInNext statement: …


Interrupting Flow of Control: Exit …

Procedures: Subs, Functions & Properties

Calling routines: Call statement


Declaring routines: Function, Sub & Property statements

Sub statement: As Basic libraries remain in memory, Global and Public scopes are equivalent.


Note:
Sub, Function or Property statements are similar methods, without distinction. They receive parameters by reference, allowing them to be modified. LibreOffice Basic compiler accepts their respective syntax to be used interchangeably.

Function statement: As Basic libraries remain in memory, Global and Public scopes are equivalent.
Property Get statement: As Basic libraries remain in memory, Global and Public scopes are equivalent.
Property Set statement: As Basic libraries remain in memory, Global and Public scopes are equivalent.

Note:
Property setters often use a single argument. Multiple arguments are equally accepted.

Arguments in routines

Argument fragment.svg
argument fragment: Syntax parameters in Function, Property or Sub statements

Tip:
Extended types such as Type statement structures, UNO services, or ClassModule objects are valid typenames.

Return values

Interrupting flow: Exit …, GoSub/GoTo, On … GoSub/GoTo statements

OnGoTo - OnGoSub statements


File System

Folders

MkDir statement
RmDir statement

Opening & Closing files

Open statement
access fragment
locking fragment
Close # statement: Closing a set of files or all files.
Reset statement: Writing buffers to disk and Closing files.
Seek # statement: Setting file offset.

Binary/Random files

Get # statement: Reading Binary or Random files.
Put # statement: Writing Binary or Random files.

Sequential files

Input # statement: Reading from file
Line Input # statement: Reading from file
Print [#] statement: Output to file or to screen with Ok and optional Cancel button.
Write # statement: Output to file

User-Defined Data Types & Classes

Objects: Type, With statements, New keyword

Type Statement: Separate datafields with new line …
Scoping with Global, Private or Public has no effect !


Class modules: constructor, destructor

Properties, Methods, Events

Error Processing

LibreOffice Basic: Erl, Err, Error, On … Error, Resume statements

On Error …


Resume statement


Calc: CvErr, IsError functions

VBA: Err object

Exception Class - e.Number=Err, e.Description=Error$, e.Source

try: … catch: … finally: …

Events Driven programming

Beyond LibreOffice Basic

Python Scripting

JavaScript Programming

Language Reference