Ask Your Question
0

Calc BASIC | How to call Function in other Library ?

asked 2020-01-14 06:27:07 +0100

lonk gravatar image

updated 2020-01-14 13:59:30 +0100

pierre-yves samyn gravatar image

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) ?

C:\fakepath\0002.ods

edit retag flag offensive close merge delete

Comments

@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.

Ratslinger gravatar imageRatslinger ( 2020-01-14 07:18:58 +0100 )edit

Dear @Ratslinger,

OMG!

I missed this Sub :

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

Khob khun krab

lonk gravatar imagelonk ( 2020-01-15 08:06:13 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-01-14 14:00:52 +0100

pierre-yves samyn gravatar image

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

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-01-14 06:27:07 +0100

Seen: 23 times

Last updated: 2 days ago