[Solved] Simple Set CheckBox to True or False

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
alb21
Posts: 6
Joined: Tue Apr 10, 2018 8:06 am

[Solved] Simple Set CheckBox to True or False

Post by alb21 »

I will appretiate very much if you guys can help me get started with oo basic programming. I've done quite a bit of excel macro programming and I am trying to move to OpenOffice but nothing seems to work. I copied this code from OpenOffice wiki but I get the following error pointing to the "oControl = oForm.getByName..." line
Basic runtime error.
An exception ocurred
Type: com.sun.star.container.NoSuchElementException
Message: .

Code: Select all

Sub SetMyCheckBox
 Dim oForm
 Dim oControl
 Dim oSheet
 Dim oCell

	oForm = ThisComponent.Sheets(0).DrawPage.Forms.getByIndex(0)
	oControl = oForm.getByName("MyCheckbox")
	oSheet = ThisComponent.Sheets(0)
	oCell = oSheet.getCellRangeByName("A1")

	If oCell.Value = "1" then
		oControl.Value = "True"
	Else
		oControl.Value = "False"
	End If
 End Sub
All I have in my spreadsheet is a CheckBox labeled and named "MyCheckBox"
Last edited by robleyd on Wed Apr 11, 2018 6:55 am, edited 1 time in total.
Reason: Tagged [Solved] [robleyd, Moderator]
Apache OpenOffice 4.1.5
Windows 10 Home
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Simple Set CheckBox to True or False

Post by Zizi64 »

Please download, install and use one of the existing object inspection tools, like the XrayTool or the MRI. Then you will able to examine the properties, methods of the programming objects.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Simple Set CheckBox to True or False

Post by UnklDonald418 »

All I have in my spreadsheet is a CheckBox labeled and named "MyCheckBox"

but your macro code

Code: Select all

oControl = oForm.getByName("MyCheckbox") 
the lower case "b" in your macro is the reason getByName() can't find the control.
If you are going to do much macro programming then follow the advice of Zizi64
[Tutorial] Introduction into object inspection with MRI
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Simple Set CheckBox to True or False

Post by Villeroy »

Simply link the check box to A1 or SheetName.A1
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
alb21
Posts: 6
Joined: Tue Apr 10, 2018 8:06 am

Re: Simple Set CheckBox to True or False

Post by alb21 »

I appretiate very much your advice. The uppercase "B" got rid of the error message of my initial question (my mistake), now the error message is in the line:

"oControl.Value = ..." Property or method not found: Value.

which I find very surprising as this code was copied from OpenOffice wiki (my only addition was creating the CheckBox on the spreadsheet).
At this moment I am downloading and installing Xray, and reading the Guides suggested by Zizi64 . After that I'll go into MRI. My hope is to finally figure out why Value is not found and what are the correct and valid names of the properties and methods I need for my purposes.
Apache OpenOffice 4.1.5
Windows 10 Home
alb21
Posts: 6
Joined: Tue Apr 10, 2018 8:06 am

[Solved] Simple Set CheckBox to True or False

Post by alb21 »

:D
I changed my line: "oControl.Value = "True"
by this new form: "oControl.State = 1"

and problem solved. I found the correct and valid names I needed in the Basic Guide, Control Element Forms in Detail, here:
https://wiki.openoffice.org/wiki/Docume ... ment_Forms

Thanks again
Apache OpenOffice 4.1.5
Windows 10 Home
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] Simple Set CheckBox to True or False

Post by Zizi64 »

I found the correct and valid names I needed in the Basic Guide, Control Element Forms in Detail, here:
The XrayTool can list all of the Properties, Methods, Services, Interfaces and Listeners "in situ".
Here is an example with a shape Object:
XrayTool2.png
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply