[Solved] Simple Set CheckBox to True or False

Creating a macro - Writing a Script - Using the API

[Solved] Simple Set CheckBox to True or False

Postby alb21 » Tue Apr 10, 2018 9:08 am

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   Expand viewCollapse view
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
alb21
 
Posts: 3
Joined: Tue Apr 10, 2018 8:06 am

Re: Simple Set CheckBox to True or False

Postby Zizi64 » Tue Apr 10, 2018 12:08 pm

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; LO4.4.7, LO5.4.7 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.0.4 and AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 6715
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Simple Set CheckBox to True or False

Postby UnklDonald418 » Tue Apr 10, 2018 5:21 pm

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

but your macro code
Code: Select all   Expand viewCollapse view
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.5 & LibreOffice 6.0.4.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 802
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Simple Set CheckBox to True or False

Postby Villeroy » Tue Apr 10, 2018 6:44 pm

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 25370
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Simple Set CheckBox to True or False

Postby alb21 » Wed Apr 11, 2018 5:50 am

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: 3
Joined: Tue Apr 10, 2018 8:06 am

[Solved] Simple Set CheckBox to True or False

Postby alb21 » Wed Apr 11, 2018 6:11 am

: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/Documentation/BASIC_Guide/Control_Element_Forms

Thanks again
Apache OpenOffice 4.1.5
Windows 10 Home
alb21
 
Posts: 3
Joined: Tue Apr 10, 2018 8:06 am

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

Postby Zizi64 » Wed Apr 11, 2018 7:08 am

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; LO4.4.7, LO5.4.7 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.0.4 and AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 6715
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests