Welcome to NeoOffice developer notes and announcements
NeoOffice
Developer notes and announcements
 
 

This website is an archive and is no longer active
NeoOffice announcements have moved to the NeoOffice News website


Support
· Forums
· NeoOffice Support
· NeoWiki


Announcements
· Twitter @NeoOffice


Downloads
· Download NeoOffice


  
NeoOffice :: View topic - Are 'global' macros for Date and Time fields possible?
Are 'global' macros for Date and Time fields possible?
 
   NeoOffice Forum Index -> NeoOffice Releases
View previous topic :: View next topic  
Author Message
GridLox
Captain


Joined: May 02, 2009
Posts: 51
Location: Adelaide, South Australia

PostPosted: Thu May 20, 2010 4:21 am    Post subject: Are 'global' macros for Date and Time fields possible?

Firstly, three cheers for the latest version NO, especially the drop-down menu for font selection - the latest font used is now clearly visible and easily accessible.

I've recently been having fun with macros and keyboard short-cuts … for entering dates and times in documents. However, it appears that the macros for these two fields only work for the document in which they were created. When I run them in a different document, either a new or and existing one, whether by keyboard short-cut or via Tools > Macros, a number (tonight it was 40318.85 - but it has varied) is produced in place of the expected result. The number is the same for each field.

Interestingly, the macro and keyboard short-cut I created for Format > Default Format works fine … I created it as, in the previous version of NO, the indicated keyboard short-cut for this operation was compromised by Mac OS X assignment).

So, do I have to rewrite the macro for every document I create or seek to modify? Or, is their some way of creating a 'global' macro for these functions?

_________________
"His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
Back to top
yoxi
Cipher


Joined: Sep 07, 2004
Posts: 1799
Location: Dawlish, Devon

PostPosted: Thu May 20, 2010 5:43 am    Post subject:

That sounds like a formatting issue to me - 40318.85 is 20:24 last night*, in how-many-days-since-the-last-day-of-1899-speke, which is what NeoOffice/OpenOffice/Excel use.

So the problem is the field needs formatting as a date field/cell - the data itself is correct.

*well, last night for you, anyway - it has yet to arrive here Smile.

Incidentally, I can't help asking - does your screen name point to some kind of digital kosher smoked salmon entity? And should we be worshipping it? Cool
Back to top
GridLox
Captain


Joined: May 02, 2009
Posts: 51
Location: Adelaide, South Australia

PostPosted: Thu May 20, 2010 7:00 pm    Post subject:

Yoxi, I clearly do have a formatting issue when the macros for both Date AND Time return the same in [quote]how-many-days-since-the-last-day-of-1899-speke[/quote]. Not only that of course, but why do the macros only work in the document for which they were created?

What I didn't mention in my initial post, was my in efforts to overcome this situation, I modified my Default Template to include the macros, verified that they worked in the Untitled document associated with the exercise, but found that they didn't function as desired in new documents created from the template. Rolling Eyes

Ah yes, my nom de plume! Actually my 'screen name' here is a variation on my preferred (and original) appellation "GridLok", which I did initially use in this forum. But when, after having not visited these pages for a while, and changed my ISP, AND wiped out my Keychain, I found I could not resume using GridLok since any communication from Trinity/NeoOffice was inevitably sent to a defunct email address. Does it point to [i]some[/i] of [quote]digital kosher smoked salmon entity[/quote]? But of course! As for whether or not it should be worshipped that is entirely optional, although I assure you and all that inquire that it is most definitely in their best interests to do so. Laughing

_________________
"His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
Back to top
pluby
The Architect
The Architect


Joined: Jun 16, 2003
Posts: 11949

PostPosted: Thu May 20, 2010 7:22 pm    Post subject:

GridLox wrote:
Yoxi, I clearly do have a formatting issue when the macros for both Date AND Time return the same in
Quote:
how-many-days-since-the-last-day-of-1899-speke
. Not only that of course, but why do the macros only work in the document for which they were created?


Macros can be created within a document. This is the default when creating a macro so that whomever else you send your document to will be able to use the macro.

Since you are using your macro as an input utility function, it makes sense to store your macro in your NeoOffice user preference files so that it is accessible to all documents. Note, however, that moving it to user preferences will mean that your macro will not be inserted into your documents so won't be able to link your macro to a button or form object.

To store a macro in your user preference files, do the following steps:

1. Open your existing macro, select all of the macro lines, copy them, and close the macro editing window.

2. Create a new macro with the copied macro lines but when NeoOffice asks you where you want to save the macro, ignore the default (which is a subfolder of the current document) and instead, save it under the My Macros :: Standard :: Module 1 folder.

3. To run the macro, select the macro from the My Macros :: Standard :: Module 1 folder in the Run Macro dialog.

Do the above steps make sense? If so, is your recreated macro accessible in all documents in that My Macros subfolder?

Patrick
Back to top
GridLox
Captain


Joined: May 02, 2009
Posts: 51
Location: Adelaide, South Australia

PostPosted: Thu May 20, 2010 7:49 pm    Post subject:

Thanks Pluby. Yes, that makes sense … and I already have the macros installed in the My Macros > Standard > Module 1 location, and they are available in all NO documents … new or old. BUT, only in those documents in which I actually created the macros for Date and Time, do they result in the current date and time. In all other documents both macros result in the 'coded' current time - whether entered 'long-hand' via menus or with the keyboard short-cuts I have established.
_________________
"His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
Back to top
yoxi
Cipher


Joined: Sep 07, 2004
Posts: 1799
Location: Dawlish, Devon

PostPosted: Fri May 21, 2010 12:23 am    Post subject:

Are you inserting a date/time field, or the actual date/time as text? Please could you post a copy of your macro here so we can take a look?
Back to top
GridLox
Captain


Joined: May 02, 2009
Posts: 51
Location: Adelaide, South Australia

PostPosted: Fri May 21, 2010 5:35 am    Post subject:

The macros seem to insert a field. I say this because whether the outcome is Date, Time, or current-time-expressed as a number string, they delete completely with a single keystroke; as opposed to text - in which characters are deleted one-at-a-time by single keystrokes.

Below are the macros for Insert Date & Insert Time:

sub InsertDate
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(5) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Type"
args1(0).Value = 0
args1(1).Name = "SubType"
args1(1).Value = 0
args1(2).Name = "Name"
args1(2).Value = ""
args1(3).Name = "Content"
args1(3).Value = "0"
args1(4).Name = "Format"
args1(4).Value = 5083
args1(5).Name = "Separator"
args1(5).Value = " "

dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args1())


end sub



sub InsertTime
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(5) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Type"
args1(0).Value = 1
args1(1).Name = "SubType"
args1(1).Value = 0
args1(2).Name = "Name"
args1(2).Value = ""
args1(3).Name = "Content"
args1(3).Value = "0"
args1(4).Name = "Format"
args1(4).Value = 5040
args1(5).Name = "Separator"
args1(5).Value = " "

dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args1())


end sub

_________________
"His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
Back to top
pluby
The Architect
The Architect


Joined: Jun 16, 2003
Posts: 11949

PostPosted: Fri May 21, 2010 7:52 am    Post subject:

Try changing the "Format" argument's value to "0" instead of "50XX". Although I find OpenOffice.org Basic syntax maddenly difficult to read, I read NeoOffice's underyling OpenOffice.org C++ code that sets the format in a new date or time field and in the format is zero, is uses Writer's default date format for date fields and HH:MM:SS format for time fields.

Does that change make your macro insert formatted date and time fields?

Patrick
Back to top
GridLox
Captain


Joined: May 02, 2009
Posts: 51
Location: Adelaide, South Australia

PostPosted: Sat May 22, 2010 3:37 am    Post subject:

Sure thing Pluby, that works … insofar as it gives Date in the format dd:mm:yy (default?) and, as you suggested Time as hh:mm:ss. I would very much prefer to have Date in the format yy:mm:dd and Time as hh:mm. Unfortunately I have absolutely no idea as to the underlying code. At this stage, I'll settle for creating a new macro for each document in which I want to enter the current date and time - as the documents concerned are journals, it will be a once-a-year task.

Perhaps the issue could be added to the wish-list of things to be done, when nobody has anything much to do (lol!!)

I wonder if it is also a problem with macros for other fields?

Thanks for your help … hopefully you (or someone) may yet think of a simple work-around.

_________________
"His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
Back to top
yoxi
Cipher


Joined: Sep 07, 2004
Posts: 1799
Location: Dawlish, Devon

PostPosted: Sat May 22, 2010 6:05 am    Post subject:

Once the date/time field is in the doc, right-click/ctrl-click on it, choose Fields from the contextual menu, and then you can edit the display format.
There should be a way to apply the desired valuefomat to the field in the macro, but I haven't found it yet.


Last edited by yoxi on Sat May 22, 2010 6:27 am; edited 1 time in total
Back to top
Lorinda
Captain Mifune


Joined: Jun 20, 2006
Posts: 2051
Location: Midwest, USA

PostPosted: Sat May 22, 2010 6:12 am    Post subject:

You might try asking at the macros forum at OpenOffice.org Community Forums, since this sounds like more of an OOo Basic issue and not a NeoOffice specific one. Those forums have several people skilled in writing macros; my guess is that someone there would have some suggestions.

Lorinda
Back to top
pluby
The Architect
The Architect


Joined: Jun 16, 2003
Posts: 11949

PostPosted: Sat May 22, 2010 10:25 am    Post subject:

I have found what is causing the problem and the problem is that this is a bug in NeoOffice's underlying OpenOffice.org 3.1.1 code. The OpenOffice.org bug is that if you have not yet manually inserted a date or time field in a document using the Insert :: Field menu, the Format codes in your macro will be ignored and you will get the unformatted timestamp.

Fortunately, there is a workaround for this OpenOffice.org bug. First, set the date format back to 5083 and the time format back to 5040 like you had ni your original macro. Then, before you use your macro for the first time in a particular document, insert a date field manually using the Insert :: Field :: Date menu. Delete this inserted field.

After you manually insert and delete a date field once in a Writer document, your macro should now work fine.

Does the above workaround work for you?

Patrick
Back to top
GridLox
Captain


Joined: May 02, 2009
Posts: 51
Location: Adelaide, South Australia

PostPosted: Sun May 23, 2010 4:18 am    Post subject:

Thanks for your interest and comments, yoxi and Lorinda.

Right on pluby! The suggested work-around works a treat. While, ideally, it would be great to have the bug fixed, I'm sure there are many more pressing matters … and not that many NO users that have my particular requirements. Meantime you have provided an eminently functional solution - much appreciated. Very Happy

Er, pluby, guess what, that fix appears to only be good for the time that the particular document is open. I went through the exercise you suggested and, as I have indicated, it worked a treat. But! when I closed the document and then re-opened it, it was back to the time-stamp!

Since I will open and close a document many times in a year, I think it probably best if I re-establish the macro for each new document in which there will be an ongoing requirement for date and time fields - thus enabling use of the assigned keyboard shortcuts. For occasional use of date/time fields I'll stick with the menu-entry methods.

_________________
"His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.


Last edited by GridLox on Sun May 23, 2010 4:32 am; edited 1 time in total
Back to top
yoxi
Cipher


Joined: Sep 07, 2004
Posts: 1799
Location: Dawlish, Devon

PostPosted: Sun May 23, 2010 4:25 am    Post subject:

You could probably save a few hand movements by including the create-and-then-delete in your macro before the real stuff Smile.
Back to top
GridLox
Captain


Joined: May 02, 2009
Posts: 51
Location: Adelaide, South Australia

PostPosted: Sun May 23, 2010 4:34 am    Post subject:

"create-and-then-delete"? Vas ist das yoxi?
_________________
"His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
Back to top
Display posts from previous:   
   NeoOffice Forum Index -> NeoOffice Releases All times are GMT - 7 Hours
Goto page 1, 2  Next
Page 1 of 2

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Powered by phpBB © 2001, 2005 phpBB Group

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest © Planamesa Inc.
NeoOffice is a registered trademark of Planamesa Inc. and may not be used without permission.
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.