[Solved] Checkbox.Visible = True Does not work

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Robitron
Posts: 105
Joined: Thu Nov 15, 2012 5:27 pm

[Solved] Checkbox.Visible = True Does not work

Post by Robitron »

Okay, I'm at a loss. I'm working with dialogs and trying to create a checkbox to add a new item to a list. The thing is, I don't want the checkbox to be visible until the list has been compiled from a column of cells in my spreadsheet. So, I've been trying for hours now just to get this to work.

Here is the code:

Code: Select all

Sub GenerateList
	Count = 1	
	Balances = Doc.Sheets.GetByName("Balances")
	GetNextItem:
	Cell1 = Balances.GetCellByPosition(0, Count)
	Select Case Cell1.String
	Case <> ""
		TDesc = oDialog.GetControl("Description")
		Count2 = TDesc.GetItemCount()
		TDesc.AddItem(Cell1.String, Count2)
		Count = Count +1
		Goto GetNextItem
	End Select
	NewAccount = oDialog.GetControl("NewAccount")
	NewAccount.Visible = True
End Sub
The thing is, the last line. If I have the NewAccount checkbox object visibility set to yes and change the line to NewAccount.Visible = False, then it hides the checkbox. However, having it set to invisible then using NewAccount.Visible = True does not work. So I don't get it. :crazy:
Last edited by Robitron on Wed Sep 26, 2018 11:52 pm, edited 1 time in total.
OpenOffice 4.1.12 on Windows 10

If I had to, I'd put Tabasco on everything!
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Checkbox.Visible = True Does not work

Post by Zizi64 »

Code: Select all

Goto
"Goto" ??????? That is a very obsolete command... Do not use it. Organize your routines without the GoTo command.

Code: Select all

Sub GenerateList
	Count = 1   
	Balances = Doc.Sheets. ...
Where you get the value of the "Doc" object variable?
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.
Robitron
Posts: 105
Joined: Thu Nov 15, 2012 5:27 pm

Re: Checkbox.Visible = True Does not work

Post by Robitron »

The Doc variable is set in the main macro that calls up the dialog box.

As for the "Goto" command, I understand it, the do while and loop and others are less easy for me to comprehend for some reason.
OpenOffice 4.1.12 on Windows 10

If I had to, I'd put Tabasco on everything!
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Checkbox.Visible = True Does not work

Post by Zizi64 »

The Doc variable is set in the main macro that calls up the dialog box.
Please upload a sample document in ODF format (with the control element), and please embed the full macro code here.
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.
Robitron
Posts: 105
Joined: Thu Nov 15, 2012 5:27 pm

Re: Checkbox.Visible = True Does not work

Post by Robitron »

Code: Select all

Option Explicit

Dim Doc as Object
Dim EntrySheet as Object
Dim Registry as Object
Dim Balances as Object
Dim Sheet as Object
Dim Cell1 as Object
Dim RDate as Date
Dim Description as String
Dim Amount as Single
Dim Balance as Single
Dim RType as String
Dim Count as Integer
Dim YesNo as Integer
Dim oLibContainer as Object, oLib as Object
Dim oInputStreamProvider as Object
Dim oDialog as Object
Const sLibName = "Standard"
Const sDialogName = "Entry_Form"
Dim ConvertDate as Object
Dim Count2 as Integer
Dim TDesc as Object
Dim NewItemCheck as Object
Dim NewAccount as Object
Dim NewItem as String

Sub EntryForm
	Doc = ThisComponent
	Registry = Doc.Sheets.GetByName("Registry")
	oLibContainer = DialogLibraries
	oLibContainer.LoadLibrary(sLibName)
	oLib = oLibContainer.GetByName(sLibName)
	oInputStreamProvider = oLib.GetByName(sDialogName)
	oDialog = CreateUnoDialog(oInputStreamProvider)
	oDialog.Execute()
End Sub

Sub DateConverter
	ConvertDate = oDialog.Model.TDate
	Select Case ConvertDate.Date
	Case 0
		End
	Case Else
		RDate = CDateFromIso(ConvertDate.Date)
	End Select
End Sub

Sub GenerateList
	Count = 1	
	Balances = Doc.Sheets.GetByName("Balances")
	GetNextItem:
	Cell1 = Balances.GetCellByPosition(0, Count)
	Select Case Cell1.String
	Case <> ""
		TDesc = oDialog.GetControl("Description")
		Count2 = TDesc.GetItemCount()
		TDesc.AddItem(Cell1.String, Count2)
		Count = Count +1
		Goto GetNextItem
	End Select
End Sub

Sub AddNewItem
	TDesc = oDialog.GetControl("Description")
	NewAccount = oDialog.GetControl("NewAccount")
	Select Case NewAccount.State
	Case 1
		NewItem = InputBox("Enter new account.", "New Account")
		AddNewItemToList
	End Select
End Sub

Sub AddNewItemToList
	TDesc = oDialog.GetControl("Description")
	Do While TDesc.GetItemCount() > 0
		Count = TDesc.GetItemCount()
		TDesc.RemoveItems(0, Count)
	Loop
	Doc = ThisComponent
	Balances = Doc.Sheets.GetByName("Balances")
	Count = 1
	FindLastRow:
	Cell1 = Balances.GetCellByPosition(0, Count)
	Select Case Cell1.String
	Case ""
		Cell1.String = NewItem
	Case <> ""
		Count = Count +1
		Goto FindLastRow
	End Select
End Sub
Sample.ods
(14.79 KiB) Downloaded 197 times
OpenOffice 4.1.12 on Windows 10

If I had to, I'd put Tabasco on everything!
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Checkbox.Visible = True Does not work

Post by JeJe »

Set the control visible to true and put the line odialog.getcontrol("NewAccount").visible =false before the oDialog.Execute() line to hide it.

An alternative to changing the visibility is to hide a control off screen eg by setting the positionx to minus the control's width.

Edit: and another alternative is to set the step of a control so it is hidden at first and then change the step of the dialog so it becomes visible.

OpenOffice has a lot of these bugs/quirks.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Checkbox.Visible = True Does not work

Post by RoryOF »

Out of interest the historical starting point for the argument against GoTo is
Edgar Dijkstra: Go To Statement Considered Harmful
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Checkbox.Visible = True Does not work

Post by JeJe »

Goto can be useful for exiting nesting loops. (If anyone has a better way...)

Code: Select all

for i = 0 to 100
for j = 0 to 100
for k = 0 to 100
if iwantoutofeverythinghere = true then goto outofalltheloops
next
next
next

outofalltheloops:

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Robitron
Posts: 105
Joined: Thu Nov 15, 2012 5:27 pm

Re: Checkbox.Visible = True Does not work

Post by Robitron »

JeJe wrote:Set the control visible to true and put the line odialog.getcontrol("NewAccount").visible =false before the oDialog.Execute() line to hide it.

An alternative to changing the visibility is to hide a control off screen eg by setting the positionx to minus the control's width.

Edit: and another alternative is to set the step of a control so it is hidden at first and then change the step of the dialog so it becomes visible.

OpenOffice has a lot of these bugs/quirks.
Thanks for that. I'm glad you tried to answer my problem, unfortunately, the problem isn't making it invisible, it's making it visible. I'll try the odialog.getcontrol("NewAccount").visible = true line and see if that works.


*Nope, still doesn't work. I can hide it but I can not reveal it.
OpenOffice 4.1.12 on Windows 10

If I had to, I'd put Tabasco on everything!
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Checkbox.Visible = True Does not work

Post by JeJe »

If you set a control to hidden and then try to show it - it doesn't work. You have to set the control to visible then hide it before you show the dialog.

Code: Select all


Sub EntryForm
	Doc = ThisComponent
	Registry = Doc.Sheets.GetByName("Registry")
	oLibContainer = DialogLibraries
	oLibContainer.LoadLibrary(sLibName)
	oLib = oLibContainer.GetByName(sLibName)
	oInputStreamProvider = oLib.GetByName(sDialogName)
	oDialog = CreateUnoDialog(oInputStreamProvider)

'**********the control is set to visible but you hide it here**********
	odialog.getcontrol("NewAccount").visible = false
	oDialog.Execute()
End Sub

Sub GenerateList
	Count = 1	
	Balances = Doc.Sheets.GetByName("Balances")
	GetNextItem:
	Cell1 = Balances.GetCellByPosition(0, Count)
	Select Case Cell1.String
	Case <> ""
		TDesc = oDialog.GetControl("Description")
		Count2 = TDesc.GetItemCount()
		TDesc.AddItem(Cell1.String, Count2)
		Count = Count +1
		Goto GetNextItem
	End Select

'**********then you can make it visible or hide it again after that**********
	odialog.getcontrol("NewAccount").visible = true 
End Sub

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Robitron
Posts: 105
Joined: Thu Nov 15, 2012 5:27 pm

Re: Checkbox.Visible = True Does not work

Post by Robitron »

Yes! Thank you so much!!! That's what the problem's been!
OpenOffice 4.1.12 on Windows 10

If I had to, I'd put Tabasco on everything!
Post Reply