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.
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.
Last edited by Robitron on Wed Sep 26, 2018 11:52 pm, edited 1 time in total.
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.
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.
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
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.
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.
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)