Basics

Ovaj odjeljak o osnovama rada sa LibreOffice Basic.

LibreOffice Basic code is based on subroutines and functions that are specified between sub...endĀ sub and function...endĀ function sections. Each Sub or Function can call other Subs and Functions. If you take care to write generic code for a Sub or Function, you can probably re-use it in other programs. See also Procedures and Functions.

Note Icon

Some restrictions apply for the names of your public variables, subs, and functions. You must not use the same name as one of the modules of the same library.


Å to je podfunkcija(Sub)?

Sub is the short form of subroutine, that is used to handle a certain task within a program. Subs are used to split a task into individual procedures. Splitting a program into procedures and sub-procedures enhances readability and reduces the error-proneness. A sub possibly takes some arguments as parameters but does not return any values back to the calling sub or function, for example:

DoSomethingWithTheValues(MyFirstValue,MySecondValue)

Å to je Funkcija?

A function is essentially a sub, which returns a value. You may use a function at the right side of a variable declaration, or at other places where you normally use values, for example:

MySecondValue = myFunction(MyFirstValue)

Globalne i lokalne varijable

Globalne varijable su valjane u svim subovima i funkcijama unutar modula. One se deklariraju na početku modula prije prvog sub-a ili početka funkcije.

Varijable koje deklariraÅ” unutar sub-a ili funkcije su važeće samo u datoj sub(rutini) ili funkciji. Te varijable će biti pretpostavljene globalnim varijablama sa istim imenom i lokalnim varijablama sa istim imenom koje potječu iz nadređenim rutinama ili funkcijama

Strukturiranje

After separating your program into procedures and functions (Subs and Functions), you can save these procedures and functions as files for reuse in other projects. LibreOffice Basic supports Modules and Libraries. Subs and functions are always contained in modules. You can define modules to be global or part of a document. Multiple modules can be combined to a library.

You can copy or move subs, functions, modules and libraries from one file to another by using the Macro dialog.

Please support us!