Calc BASIC | How to call Function in other Library?

Code

'Library1 Module1'
Option Explicit
Sub TestConnectingEmbeddedFirebird1
	Dim iBox%
	iBox = MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION
	If MsgBox ("Do you want to connect embedded Firebird database ?", iBox) = IDYES Then
		On Local Error GoTo CloseConn
		Dim db As Object : db = Library2.Module1.ConnectDatabase("firebird0")
		MsgBox "Embedded Firebird database connected"
		DisconnectDatabase(db)
		MsgBox "Embedded Firebird database disconnected"
	Else
		MsgBox "No embedded Firebird database connected"	
	End IF
	Exit Sub
CloseConn:
	MsgBox "Error " & Err & ": " & Error$ & " (line : " & Erl & ")"
	DisconnectDatabase(db)
End Sub

Sub TestConnectingEmbeddedFirebird2
	On Local Error GoTo CloseConn
	Dim db As Object : db = Library2.Module1.ConnectDatabase("firebird0")
	DisconnectDatabase(db)
	Exit Sub
CloseConn:
	MsgBox "Error " & Err & ": " & Error$ & " (line : " & Erl & ")"
	DisconnectDatabase(db)
End Sub

'Library2 Module1'
Option Explicit
Function ConnectDatabase(dbFilename$) As Object
	Dim dbContext 	As Object 	: dbContext 	= createUNOService("com.sun.star.sdb.DatabaseContext")
	Dim oDataSource As Object 	: oDataSource 	= dbContext.GetByName(dbFilename)
	ConnectDatabase = oDataSource.GetConnection("","")'("Username","Password")
End Function

Sub TestConnectingEmbeddedFirebird1 or Sub TestConnectingEmbeddedFirebird2 sent the error message:

image description

image description

image description

image description

How can we call Function in other Library (and in order to connect embedded Firebird database) ?

0002.ods

@lonk,

Maybe missing something here but the error message for indicated lines contain:

DisconnectDatabase(db)

and there is no such function/sub in the code for this.

Dear @Ratslinger,

OMG!

I missed this Sub :

Sub DisconnectDatabase(db)
	db.Close
	db.Dispose()
End Sub

Khob khun krab

Hi

The Standard library is the only one to be loaded automatically when opening a document. The others must be loaded by an instruction such as :

   If Not BasicLibraries.isLibraryLoaded("Library1") then
      BasicLibraries.loadLibrary("Library1")
   Endif

Regards