Can't a globally accesible dialog variable

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
RobberFox
Posts: 1
Joined: Wed Nov 20, 2024 8:50 am

Can't a globally accesible dialog variable

Post by RobberFox »

I have this code:
```basic

Code: Select all

Dim oDialog1

Sub StartDialog1
	BasicLibraries.LoadLibrary("Tools")
	oDialog1 = Tools.LoadDialog("Standard", "HelloDlg")
    oDialog1.Execute()
End Sub

Sub ExitDialog
	oDialog1.endExecute()
End Sub
```
But when using `ExitDialog` event handler I get an error that my `oDialog1` object variable is not set. What's wrong?
Last edited by robleyd on Wed Nov 20, 2024 9:31 am, edited 1 time in total.
Reason: Add CODE tags
LibreOffice 7.4.7.2 40(Build:2)
Debian 12 (bookworm)
ms777
Volunteer
Posts: 199
Joined: Mon Oct 08, 2007 1:33 am

Re: Can't a globally accesible dialog variable

Post by ms777 »

:super: Replace

Code: Select all

Dim oDialog1
by

Code: Select all

Global oDialog1 
JeJe
Volunteer
Posts: 2938
Joined: Wed Mar 09, 2016 2:40 pm

Re: Can't a globally accesible dialog variable

Post by JeJe »

It can be simpler to avoid a global variable. If you're calling the sub from a button you pressed on the dialog you can get the dialog from the event without needing one.

Code: Select all

Sub ExitDialog(ev)
	ev.source.getcontext.endExecute()
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply