[Solved] How to control a file within hidden frame

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

[Solved] How to control a file within hidden frame

Post by sokolowitzky »

I can open files as hidden with this function below.
But I can not manage them since I don't know how to control files with hidden frames.
For example This code below, it can not close the file that it has already opened.
Anyone with an idea?

Code: Select all

global ddoc1 as object
global ddoc2 as object
sub urbann

objo1 = "C:\Users\Sokolowitzky\Files\file1.ods"
objo2 = "C:\Users\Sokolowitzky\Files\file2.ods"
opener(objo1)
ddoc1 = StarDesktop.CurrentComponent
opener(objo2)
ddoc2 = StarDesktop.CurrentComponent

ddoc1.close(true)
ddoc2.close(true)
end sub

function opener(objo)
dim ddoc1 as object
dim Props(1) As New com.sun.star.beans.PropertyValue
OBJurl = converttourl(objo)
Props(1).Name="Hidden" : Props(1).Value=True
'msgbox objurl
ddoc1 = stardesktop.loadcomponentfromurl(OBJurl, "_blank", 0, PROPS())
ddoc1.CurrentController.Frame.ContainerWindow.setVisible(FALSE)
End function 
Last edited by sokolowitzky on Fri Nov 30, 2018 10:31 pm, edited 2 times in total.
Win10-OpenOffice 4.1/LibreOffice 7.4
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: How to control a file within hidden frame

Post by Lupp »

Sorry.
Your code simply is nonsense. Both your globel variables end up representing the Basic IDE.
Rethink the matter thoroughly. There are additional issues.
Last edited by Lupp on Thu Nov 29, 2018 11:42 am, edited 1 time in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to control a file within hidden frame

Post by JeJe »

You need to put

Code: Select all

opener=ddoc1
at the end of your opener function.

And then in the urbann sub you put ddoc1 = opener(objo1)

simplifying everything a bit, something like:

Code: Select all

global ddoc1 as object

sub urbann
objo1 = "C:\Users\Sokolowitzky\Files\file1.ods"
ddoc1 = opener(objo1)
ddoc1.close(true)
end sub

function opener(objo as string)
dim Props(0) As New com.sun.star.beans.PropertyValue
dim OBJurl as string
OBJurl = converttourl(objo)
Props(0).Name="Hidden" : Props(0).Value=true
opener = stardesktop.loadcomponentfromurl(OBJurl, "_blank", 0, PROPS())
End function 
Edit: simplified a bit more.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: How to control a file within hidden frame

Post by Lupp »

I would suggest to use a "working document" containing the relevant constants (pathnames, parameters for any actions to perform ...) and most likely also the code. I would not try to run the code with all the needed parameters or with a lot of dialogues from the StarDesktop. In my example the working file is a text document f0.odt "just for fun". It works on the two files f1.odt and f2.odt which must be found in the same folder. For providing parameters a spreadsheet document is preferrable, of course.

See attachment. I tried to give an example regarding some kind of "good style". It's Lupp style, however.
Expand the archive to an empty folder and run f0.odt, Sub test if you want to try my suggestion.

If you want to continue programming for OpenOffice/LibreOffice, study the API and -at least- the famous texts by Andrew Pitonyak.
Attachments
aoo96058sokolowitzky.zip
(21.49 KiB) Downloaded 106 times
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to control a file within hidden frame

Post by JeJe »

Oh dear Lupp!

Code: Select all

doc1.Text.InsertString(tC1, " Kilroy was here.", Fale)
You get away with it here but what about if you put Tre!

And props(0)!

(Just kidding... we all do these typos!)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: How to control a file within hidden frame

Post by Lupp »

Holy smokes! Even when I had "read" your post, and in specific the quoted code half a dozen times I was bewildered, but had no clue. Still considering if the problem was due to my age or to the fact that my English is that poor, my eye took over from the brain and focused the "Fale". Thanks!

Well, the missing transition to "props(0)" in 'Dim' and usage as well was left over from sokolowitzky's code and won't do any harm. Nonetheless I was obliged to rectify it, of course. Congratualtions to you! Good eye and brain.

However, I have to refute your claim that "...we all do these typos." You seem to be the exception.

Going through my faulty code once more I found another line where as much as two closing parentheses were missing. (StarBasic is too error-tolerant with parentheses at the end of a line. I would judge this to be a bug.)
Last edited by Lupp on Thu Nov 29, 2018 1:13 pm, edited 1 time in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to control a file within hidden frame

Post by JeJe »

I'm no exception... for speed I don't usually bother with Option Explicit and sometimes spend ages looking for what turns out to be a variable name typo. Then I put Option Explicit at the top later and tidy everything up. Possibly not the best way...
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: How to control a file within hidden frame

Post by Lupp »

Concerning the Option Explicit I once read a blog where the author ( I forgot the name, of course) announced his departure from using that option. He emphasised the false sense of security coming with it. It's a point. We cannot trust in our testing if the code contains some branching anyway, and we cannot trust in not having missed the occurrence of a not declared variable, too, therefore. It's one of the many shortcomings of our Basic that it does_not/cannot check for missing declarations abstractly.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

Re: [Solved]How to control a file within hidden frame

Post by sokolowitzky »

@Jeje Thank you very much. I felt like I should use something in the function but I thought that It was supposed to be related with frames etc. I couldn't imagine that it could be this simple.
@Lupp thank you very much. This serves answers to more than one question. For example I could not use the split statement now it makes sense.
About the programming? I have no programming background and even though I still use Pitonyak's book, his examples are many times over my capacity.
I need something like "Openoffice Basic for Dummies", "Cooking with macros", "Alice in Macroland" etc.
Win10-OpenOffice 4.1/LibreOffice 7.4
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved]How to control a file within hidden frame

Post by Zizi64 »

I need something like "Openoffice Basic for Dummies",
The existing StarBasic commands and statements are well descripted in the Help of the Basic IDE. The StarBasic is not a difficult language: there is not too many commands and statements.

But you need study the thousands of the API functions and procedures. (You can call them from all of the supported programming languages, or even from outside the AOO too.)
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.
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] How to control a file within hidden frame

Post by Lupp »

Glad if my examples helped - and sorry for my harsh first comment.

However there are isues - as next to always with programming. Not for nothing EVERY software is buggy.

In the current case a thorough design of the custom code would (at least) require additionally to check if any file to work on is already opened, and to take proper measures if so. Opening an already open file a second time will silently set the read-only flag. The editing commands will then be performed -probably needing an hour- but the result cannot be saved.

You will surely find additional issues...
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply