$USELIBRARY

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search

The $USELIBRARY metacommand is used to easily include a library from our dedicated QB64-PE Libraries Pack add-on into your code.


Syntax

$USELIBRARY:'author/library'


Parameters

IMPORTANT
  • The parameter must be enclosed in single quotes and given as literal string, variables cannot be used here.
  • Your input is checked while typing to ensure its validity, warnings (if any) will be displayed immediately in the IDE status area.
  • The author/library designates the library to include by author / library name as organized in the QB64-PE Libraries Pack add-on.
    • Easiest is to call the Library Explorer from the IDE's tools menu (or Ctrl-L), choose the library to use and simply copy the generated $USELIBRARY line there and paste it into your code.


Description

  • Usually you have to manually include 3rd party libraries by placing the respective $INCLUDE lines into your code.
    • In most cases that are two includes, one at the top of your code, another one at the bottom.
    • In some rare cases a library could have another file, which must go into the middle of your code.
  • Note that this traditional way of including libraries works unchanged as is and is still required to be used if:
    • You don't have installed the QB64-PE Libraries Pack add-on.
    • The library you wanna use is not (yet) in the Pack.
    • You hang on to any old QB64-PE versions and for some reason don't wanna upgrade to QB64-PE v4.3.0 or up.
  • If you otherwise use QB64-PE v4.3.0 or up and also have installed the QB64-PE Libraries Pack add-on, then you're ready to use the $USELIBRARY metacommand, well as far as the library of interest is in the Pack.
    • It's just one line now and be done, QB64-PE will take care of the rest. Doesn't matter of how many files the library consists, QB64-PE knows which file must be included in which place in your program and will do so automatically.
    • The best of all, you must not even type the $USELIBRARY command, just call the Library Explorer from the IDE's tools menu (or Ctrl-L), choose the library to use and simply copy the generated $USELIBRARY line there and paste it into your code.
  • The command can be placed everywhere in your program, but of course it should be before the first use of the library's functions.
  • $USELIBRARY can even be used inside other included files, e.g. a library could pull in other libraries it depends on.


Availability


Examples

Example
Using the $USELIBRARY metacommand to include the INI-Manager and performing some action with the included library.
Note
This example needs the QB64-PE Libraries Pack add-on installed to work.
$IF VERSION < 4.3.0 THEN
    $ERROR "The Libraries Pack add-on needs at least QB64-PE v4.3.0"
$END IF 

$USELIBRARY:'FellippeHeitor/IniManager'

file$ = "./settings/config.ini"
sect$ = "[IDE DISPLAY SETTINGS]"

'----------------------------------------------------------------
'syntax: var$ = Ini_ReadSetting(file$, "[section]", "")
'
'You can read all keys/values from a specific section by calling
'Ini_ReadSetting with an empty key$ value.
'----------------------------------------------------------------
PRINT "Reading the QB64-PE config file and"
PRINT
COLOR 9
PRINT "fetch only section "; sect$; ":"
DO
    a$ = Ini_ReadSetting$(file$, sect$, "")

    'NOTE: If you would check dot values of the __ini TYPE inside a SUB or FUNCTION,
    '      then remember to explicitly do a SHARED __ini in the respective routine.
    IF __ini.code = 1 THEN PRINT Ini_GetInfo$: END '__ini.code = 1 -> File not found
    IF __ini.code = 10 THEN EXIT DO '__ini.code = 10 -> No more keys found
    IF __ini.code = 14 THEN PRINT Ini_GetInfo$: END '__ini.code = 14 -> Section not found

    COLOR 7
    PRINT __ini.lastSection$;
    COLOR 15: PRINT __ini.lastKey$;
    COLOR 4: PRINT "=";
    COLOR 2: PRINT a$
LOOP
COLOR 9
PRINT "End of section."

END
Explanation
 Although the INI-Manager library consists of two distinct files, we did
 not care to $INCLUDE them in our code. Instead we just told QB64-PE that
 we wanna use that library and it took care of correctly including it.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link