Een overzicht van een programma in Apache OpenOffice BASIC

From Apache OpenOffice Wiki
< NL‎ | Documentation‎ | BASIC Guide
Revision as of 13:48, 20 January 2013 by DiGro (Talk | contribs)

Jump to: navigation, search
Book.png

Apache OpenOffice BASIC is een interpreter-taal. Anders dan C++ of Delphi, maakt de Apache OpenOffice BASIC-compiler geen uitvoerbare of zichzelf uitpakkende bestanden die in staat zijn om automatisch te worden uitgevoerd. In plaats daarvan voert u een programma in Apache OpenOffice BASIC uit binnen Apache OpenOffice. De code wordt eerst gecontroleerd op duidelijke fouten en dan regel voor regel uitgevoerd.

Programmaregels

De BASIC-interpreter's regel-georiënteerde uitvoering produceert één van de belangrijkste verschillen tussen BASIC en andere programmeertalen. Waar de positie van harde regeleinden in de broncode van programma's in Java, C++ of Delphi niet relevant is, vormt elke regel in een programma van BASIC zichzelf bevattende eenheid. Functie-aanroepen, rekenkundige uitdrukkingen en andere taalkundige elementen, zoals koppen voor functies en loops, moeten op dezelfde regel worden voltooid als die waarop zij beginnen.

Indien er niet voldoende ruimte is of indien dit resulteert in lange regels, dan kunnen verschillende regels worden gekoppeld door underscores _ toe te voegen. Het volgende voorbeeld geeft weer hoe vier regels van een rekenkundige bewerking kunnen worden gekoppeld:

LongExpression = (Expression1 * Expression2) + _
(Expression3 * Expression4) + _ 
(Expression5 * Expression6) + _
(Expression7 * Expression8)

Template:Documentation/Note

In aanvulling op het koppelen van individuele regels kunt u in Apache OpenOffice BASIC dubbele punten gebruiken om een regel in verschillende gedeelten op te delen, zodat er voldoende ruimte is voor verscheidene uitdrukkingen. De toewijzingen

a = 1 
a = a + 1 
a = a + 1 

kunnen als volgt worden geschreven:

a = 1  :  a = a + 1  :  a = a + 1

Opmerkingen

In aanvulling op de programmacode die moet worden uitgevoerd, kan een Apache OpenOffice BASIC-programma ook opmerkingen bevatten die de individuele deken van het programma uitleggen en belangrijke informatie verschaffen die in een later stadium behulpzaam kan zijn.

Apache OpenOffice BASIC verschaft twee methoden voor het invoegen van opmerkingen in de programmacode:

  • Alle tekens die volgen op een apostrof worden behandeld als opmerkingen:
    Dim A    ' Dit is een opmerking voor variabele A
  • Het sleutelwoord Rem, gevolgd door de opmerking:
    Rem Deze opmerking wordt voorafgegaan door het sleutelwoord Rem.

Een opmerking omvat normaal gesproken alle tekens tot aan het einde van de regel. Apache OpenOffice BASIC interpreteert dan de volgende regel weer opnieuw als een reguliere instructie. Indien opmerkingen meerdere regels omvatten moet elke regel worden geïdentificeerd als een opmerking:

Dim B     ' Deze opmerking voor variabele B is relatief lang
          ' en strekt zich uit over meerdere regels. Het
          ' teken voor een opmerking moet daarom worden herhaald 
          ' in elke regel.

Markers

A Apache OpenOffice BASIC program can contain dozens, hundreds, or even thousands of markers, which are names for variables, constants, functions, and so on. When you select a name for a marker, the following rules apply:

  • Markers can only contain Latin letters, numbers, and underscores (_).
  • The first character of a marker must be a letter or an underscore.
  • Markers cannot contain special characters, such as ä â î ß.
  • The maximum length of a marker is 255 characters.
  • No distinction is made between uppercase and lowercase characters. The OneTestVariable marker, for example, defines the same variable as onetestVariable and ONETESTVARIABLE.
    There is, however, one exception to this rule: a distinction is made between uppercase and lowercase characters for UNO-API constants. More information about UNO is presented in Introduction to the Apache OpenOffice API.


Documentation caution.png The names of the Basic modules (by default Module1, Module2, etc) are known by Basic on a public scope. You must avoid to have a marker of public scope with the same name as one of the modules of the library.

Example : Suppose that in your Basic library you have a module named PrintDoc. You must not declare, in any module of your library, a Public variable or a Public constant, or a Sub, or a Function, named PrintDoc.

If you do have such collision, BASIC may produce strange runtime error messages, or your Sub may not work.

Documentation note.png VBA : The rules for constructing markers are different in Apache OpenOffice Basic than in VBA. For example, Apache OpenOffice BASIC only allows special characters in markers when using Option Compatible, since they can cause problems in international projects.


Here are a few examples of correct and incorrect markers:

Surname      ' Correct 
Surname5     ' Correct (number 5 is not the first digit)
First Name   ' Incorrect (spaces are not permitted)
DéjàVu       ' Incorrect (letters such as é, à are not permitted)
5Surnames    ' Incorrect (the first character must not be a number)
First,Name   ' Incorrect (commas and full stops are not permitted)

Enclosing a variable name in square brackets allows names that might otherwise be disallowed; for example, spaces.

  Dim [First Name] As String  'Space accepted in square brackets
  Dim [DéjàVu] As Integer     'Special characters in square brackets
  [First Name] = "Andrew"
  [DéjàVu] = 2


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools