Issue 70167

Summary: Macro recorder inserts date from "Insert - Fields - Other - Card 'Document' - Date" with wrong format
Product: Writer Reporter: steveh_66 <shause2>
Component: programmingAssignee: AOO issues mailing list <issues>
Status: CONFIRMED --- QA Contact:
Severity: Trivial    
Priority: P3 CC: issues, michel.franckart, pagalmes.lists, rainerbielefeld_ooo_qa
Version: OOo 2.0.3Keywords: needhelp, oooqa
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---
Issue Depends on:    
Issue Blocks: 81517    
Attachments:
Description Flags
screenshots showing different view after first macro execution and reopen of the document
none
test and demonstration kit as announced none

Description steveh_66 2006-10-06 21:06:38 UTC
OK, I think that this date and time in a macro thing is a bug. Here is what I do
to make the macro:

I click on tools > macro > record macro
I click on the toolbar button to center my text
I click on insert > fields > other, and then I select the type of date that I
want, leaving it set as fixed
I close the fields box, which is what was opened up to select the type of date I
want
I put in 5 tabs
I click on insert > fields > other, and then I select the type of time that I
want, leaving it set as fixed
I close the fields box
I hit enter twice to give me a blank line and put the cursor on a second line
I click on the left justify button on the toolbar, to left justify my text
I click on stop recording macro and name my macro

OK. In past versions of Open Office, this worked great when done exactly as I
described above. (The following examples just aren't formatting the way I use
them). Any time I opened up a new document, I could run this macro and get the
date and time in the format I wanted, for example:
Fri, October 06, 2006 6:55 PM

When I first record the macro in ver. 2.0.3, it works great in the document I
recorded it in. Can use it repeatedly and it works. Can save the document and
open it later, and it works fine. But in a new document it puts in the raw data
like:

38995.79 38995.79

It also does this in a document that I create the macro in and use the macro in
(and it works great in the document as long as it is in Open Office Writer
format) but if I use 'save as' and save the document in another format such as
.rtf then it doesn't work - again it puts the data in raw format.

Now I HAVE found a workaround:

You use the macro in a new document. It puts the data in as raw data, but spaced
and everything the way you wanted it. You select one of the fields and right
click, and on the pop-up menu that comes up you select fields, and go back and
reselect the date in the format you want and click on OK. At this point, it
doesn't change it back, it stays as the raw data format. Then, you click on view
> field names. Now, the fields go to this format :

Date (fixed) Time (fixed)

OK. Now, you go back and click on view > field names (which deselects viewing as
field names) again, and after you do this it changes back, but instead of the
raw data format you get the date in the format you want and the time in the
format you want, spaced and laid out the way you wanted it to.

Of course this is a lot of steps to go through in a document where you might
only want to use the date and time once. Better to just Insert the data and
insert the time, laying it out in whatever arrangement you want to have it in
manually. Lot less work and a lot less steps. I tried doing the macro in a blank
new document, erase everything and then save that document as the default
document. But this doesn't work as a work-around, you get the raw data and have
to go through the work-around I described above. The following is the macro text
you get when you click on edit in the macro window :

Begin Macro Code
---------------------------------------------------------------------

REM ***** BASIC *****

Sub Main

End Sub







sub DateTime
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(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "CenterPara"
args1(0).Value = true

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

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

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

rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Text"
args3(0).Value = CHR$(9)+CHR$(9)+CHR$(9)+CHR$(9)+CHR$(9)

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args3())

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

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

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())

rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "LeftPara"
args7(0).Value = true

dispatcher.executeDispatch(document, ".uno:LeftPara", "", 0, args7())


end sub

End Macro Code
----------------------------------------------------------------------------

I researched through the forums and couldn't find a way to fix this. I found a
lot of posts where people said download my macros and use them. Or showed their
macro code in the post itself
Comment 1 Rainer Bielefeld 2006-10-07 08:21:29 UTC
Not P1

Comment 2 Rainer Bielefeld 2006-10-07 09:09:01 UTC
I checked with "2.0.2  German version WIN XP: [680m5(Build9011)]" and foud, that
the macro from th report creates fields with standard number formatting. When I
save and reopen the document, the date and time will be shown in my standard
format. 

Steps to reproduce:
1. open new text document
2. Menu "Tools - macros - organize macros - OOo"
3. Select your document "untitled" / Standard
4.  <NEW>
5. Leave default name and <OK>
6. Press <Enter> 2 times and insert reported macro text from "sub DateTime" to 
   "end sub"
7. Close edit window
8. Run macro
   Expected (as per report, not due to marco contents): 2 Fields with 
   date / time format
   Actual: 2 floating point numbers
9. Save document as "myowntest.odt" and close it.
10. reopen
    expected: 2 floating point numbers
    actual: date / time format

I was not able to create a macro showing the same effect with a.m. versions.

@steveh_66
The macro you contributed as text does not show date/time format at first
execution in any OOo version. 
Do I understand you correct that you want to report that the problem is that the
macro recorder does not work correctly in 2.0.3? If yes, please write a more
meaningful summary like "Macros created with macro recorder 2.0.3 show wrong
number format" or similar.

Please reduce your report and macro to the essential parts (is it really
important to insert *5* tabs or is the result the same with 4, 6, no Tab ;-) ?)
Comment 3 Rainer Bielefeld 2006-10-07 09:09:59 UTC
Created attachment 39621 [details]
screenshots showing different view after first macro execution and reopen of the document
Comment 4 Rainer Bielefeld 2006-10-07 14:47:03 UTC
Additionally did some further tests with "2.0.4RC1 German version WIN XP:
[680m3(Build9066)]" and now I was able to reproduce the problem. It's rather simple:

1. open new WRITER document
2. Start Macro recorder
3. Insert Field by Menu "Insert - Fields - Other - Card 'Document' - Date"
4. Select format "31.12.1999" (or any other)
5. <Insert> (closes fields dialogue)
6. <Enter>
7. Close Macro recorder and save Macro for this document.
9. Menu "Tools - Macros - Organize - OOo" and select your macro
10. Mark from "sub" ... to "end sub"
11. <cntrl>+<c>
12. open new WRITER document 
13.  Menu "Tools - Macros - Organize - OOo"
14. Select your document and create NEW
15. replace empty sub by <cntrl>+<v>
16. close macro dialogue
17. run macro
    expected: date should be inserted to document with format "31.12.1999"
    actual: date will be inserted to document with format "decimal number"

If you do the test 1. to 17. but use Menu "Insert - Fields - Date" directly from
Insert menu in step 3 and continue with step 6, in step 17 the date will be
shown with format "31.12.1999" as expected.

The created basic code is completely different with the second method, my basic
knowledge is too poor to decide what the reason might be.

I will attach a test kit with:
- 'test202_macropastedwithdatefromotherselection.odt'
  containing a macro created with the first experiment 1 ... 17
  test202_macrosourcewithdatefromotherselection.odt
  with wrong date format in (pasted) macro created date

- test202_macrosourcewithdatefrommenu.odt
  containing a macro created with the second experiment 1 ... 17
  test202_macropastedwithdatefrommenu.odt
  with correct date format in (pasted) macro created date

@steveh_66:
It seems that no further activity is required.
Comment 5 Rainer Bielefeld 2006-10-07 14:48:27 UTC
Created attachment 39624 [details]
test and demonstration kit as announced
Comment 6 stefan.baltzer 2006-10-09 13:12:08 UTC
SBA: Set target OOo 2.x.
Comment 7 steveh_66 2006-10-10 04:36:58 UTC
rainerbeilefeld, I can assure you that the problem works just as I described. 
What's the difference if I have 5 tabs in my macro to get the formatting I want
or 4 or 6?  I enclosed a description of how the macro was written and a copy of
the macro itself, as copied from the macro edit function.  Most people who are
debugging a problem want as much information about the problem as possible, I do
believe that this is the first time I ever reported a bug and was asked to
provide LESS information ;-)  And if I use insert > fields > other > date and
leave it in the regular date format then it works fine for me too.  But it
updates the date to the current time and date every time I open the document.  I
don't want this, I want fixed date and time, so I can remember what day and time
I wrote something.  And if I use fixed date and fixed time, I assure you that on
my system it performs just like i reported in my bug report.  I can send screen
captures if you want,,,lol
Comment 8 michael.ruess 2006-10-10 06:41:32 UTC
Reassigned to JSK.
Comment 9 shermluge 2007-09-28 21:09:49 UTC
Is there code for a work around in OO Basic?

Thanks Sherm
Comment 10 hans_werner67 2011-03-28 11:51:27 UTC
Assign to new default-assignee
Comment 11 eric.savary 2011-04-11 07:19:08 UTC
Reassigned to TBO.
Comment 12 b.osi.ooo 2011-04-11 12:54:27 UTC
Assigning to developer of Issue #81517 - [Meta] [Writer] Macro recorder functions not recorded properly
There is nothing I can do about that;
Comment 13 b.osi.ooo 2011-04-11 13:31:04 UTC
*** Issue 102560 has been marked as a duplicate of this issue. ***
Comment 14 Marcus 2017-05-20 11:19:47 UTC
Reset assigne to the default "issues@openoffice.apache.org".