OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

backup save with time stamp

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
schelle
General User
General User


Joined: 30 Oct 2003
Posts: 45
Location: Australia

PostPosted: Fri Apr 09, 2004 1:58 am    Post subject: backup save with time stamp Reply with quote

Dear wonderful macro writers,

I have another challenge for you (loud groans all round).

Your previous work on the macro to save in different formats is FANTASTIC and I use it happily every day. However, I have come up with another idea that would be very useful. I wonder if you can help me?

I would like a macro that automatically saves the open document every 15 minutes, using the name of the open file but adding a date and time stamp. Is this possible?

I would like these 'backup' copies to be saved as .rtf files, which will reduce storage size, and mean they can be opened with most software. Ideally, the macro would create a new folder for the open document (with the same name & in the same area as the open document) in which backups for that document are saved.

As always I will understand if I am asking too much... but that doesn't stop me hoping : )
_________________
"Poetry is the journal of a sea animal living on land, wanting to fly in the air."
(Carl Sandberg)
Back to top
View user's profile Send private message Visit poster's website
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Fri Apr 09, 2004 6:06 am    Post subject: Reply with quote

I don't believe there is any good way, using only OOo Basic, to automatically save every XX minutes.

Perhaps a component could be written that would fire a timer event to Basic that could enable such magic. I have lamented the lack of a timer control several times here on OOoForum.

Remember the older macro to save in three formats? It is located here....
http://www.oooforum.org/forum/viewtopic.php?p=13524#13524


What follows is a trivial variation on that macro which adds a timestamp to the saved files....
Code:
Sub Main
   oTextDoc = ThisComponent
   cDocumentTitle = oTextDoc.getDocumentInfo().Title
   
   If Len( cDocumentTitle ) = 0 Then
      MsgBox( "You need to set the document title first.  Pick File -> Properties -> Description -> Title." )
      Exit Sub
   EndIf
   
   cFolderToSave = "c:\documents and settings\dbrewer\desktop"
   cBackupFolder = "c:\documents and settings\dbrewer\desktop\backup"
   
   cDocumentTitle = cDocumentTitle + "-" + TimeStamp()
   
   ' Save the document as SXW
   cURL = ConvertToURL( cFolderToSave + "\" + cDocumentTitle + ".sxw" )
   oTextDoc.storeAsUrl( cURL, Array() )
   
   ' Save a backup as SXW
   cURL = ConvertToURL( cBackupFolder + "\" + cDocumentTitle + ".sxw" )
   oTextDoc.storeToUrl( cURL, Array() )
   
   ' Save a backup as RTF
   cURL = ConvertToURL( cBackupFolder + "\" + cDocumentTitle + ".rtf" )
   oTextDoc.storeToUrl( cURL, Array( MakePropertyValue( "FilterName", "Rich Text Format" ) ) )
   
   ' Save a backup as DOC
   cURL = ConvertToURL( cBackupFolder + "\" + cDocumentTitle + ".doc" )
   oTextDoc.storeToUrl( cURL, Array( MakePropertyValue( "FilterName", "MS WinWord 6.0" ) ) )
   
   ' Save a backup as a PDF
   cURL = ConvertToURL( cBackupFolder + "\" + cDocumentTitle + ".pdf" )
   oTextDoc.storeToUrl( cURL, Array( MakePropertyValue( "FilterName", "writer_pdf_Export" ) ) )
End Sub


'   Create and return a new com.sun.star.beans.PropertyValue.
'
Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
   oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   EndIf
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   EndIf
   MakePropertyValue() = oPropertyValue
End Function

Function Timestamp()
   dDate = Date()
   tTime = Time()
   Timestamp = TwoZeroLeftFill(Year(dDate)) + "-" + TwoZeroLeftFill(Month(dDate)) + "-" + TwoZeroLeftFill(Day(dDate)) _
         + "-" _
         + TwoZeroLeftFill(Hour(tTime)) + "-" + TwoZeroLeftFill(Minute(tTime)) + "-" + TwoZeroLeftFill(Second(tTime))
End Function

Function TwoZeroLeftFill( nNum )
   TwoZeroLeftFill = ZeroLeftFill( nNum, 2 )
End Function

Function ZeroLeftFill( nNum, nZeros )
   cString = CStr( nNum )
   Do While Len( cString ) < nZeros
      cString = "0" + cString
   Loop
   ZeroLeftFill = cString
End Function

_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
schelle
General User
General User


Joined: 30 Oct 2003
Posts: 45
Location: Australia

PostPosted: Fri Apr 09, 2004 6:40 pm    Post subject: Reply with quote

Thanks Danny,

The other page which is relevant to the very useful macro mentioned above is:
http://www.oooforum.org/forum/viewtopic.php?t=3635&highlight=useful+macro

With the time stamp variation above, is it possible that the cut & paste could be causing problems? I deleted all the spaces at the end of lines, which have caused problems in the past, but I am still getting a "BASIC syntax error. Unexpected symbol: +." The highlighted symbol is the one in red below:

Function Timestamp()
dDate = Date()
tTime = Time()
Timestamp = TwoZeroLeftFill(Year(dDate)) + "-" + TwoZeroLeftFill(Month(dDate)) + "-" + TwoZeroLeftFill(Day(dDate))
+ "-"
+ TwoZeroLeftFill(Hour(tTime)) + "-" + TwoZeroLeftFill(Minute(tTime)) + "-" + TwoZeroLeftFill(Second(tTime))
End Function[/url]
_________________
"Poetry is the journal of a sea animal living on land, wanting to fly in the air."
(Carl Sandberg)
Back to top
View user's profile Send private message Visit poster's website
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Apr 10, 2004 5:32 am    Post subject: Reply with quote

See the underscores at the end of some lines. Those are important.

The line that starts with....

Timestamp = TwoZeroLeftFill(Year( ........ _

Takes up three lines. The first line ends with an underscore, so that the line may be continued onto a second line which says.....

+ "-" _

That second line ends with an underscore so that it may be continued onto a third line which says.....

+ TwoZeroLeftFill(Hour(tTime)) .........rest deleted.....

Lines that end with an underscore, so that they may continue onto the next line, need to have that underscore as the very last character on the line with no trailing spaces following the underscore.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
schelle
General User
General User


Joined: 30 Oct 2003
Posts: 45
Location: Australia

PostPosted: Sat Apr 10, 2004 7:47 pm    Post subject: Reply with quote

COOL! That worked : )

Thanks, Danny. I don't know how those two underscores disappeared, since I copied and pasted the whole piece of code as a block... but once I put them back everything worked fine. I'll know what to look for next time!!!

PS. I've just upgraded to OOo 1.1.1. When I filled out my registration survey I mentioned the need for the timer event component you were talking about...
_________________
"Poetry is the journal of a sea animal living on land, wanting to fly in the air."
(Carl Sandberg)
Back to top
View user's profile Send private message Visit poster's website
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sun Apr 11, 2004 6:13 am    Post subject: Reply with quote

You can also remove the underscores, and merge the multiple lines back onto one single long line.

When writing code, sometimes the programmer does not want one looooooong line of code which can be difficult to read. So a line of code may be broken into multiple lines. In this case, the underscore is necessary to tell the compiler that this line is not finished yet.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
schelle
General User
General User


Joined: 30 Oct 2003
Posts: 45
Location: Australia

PostPosted: Sun Apr 11, 2004 6:25 pm    Post subject: Reply with quote

Understood...

I don't know much about programming - that's more my husband's field - but I write HTML with notepad, so I have some small idea of what's involved : )

Your help is, as always, greatly appreciated.
_________________
"Poetry is the journal of a sea animal living on land, wanting to fly in the air."
(Carl Sandberg)
Back to top
View user's profile Send private message Visit poster's website
schelle
General User
General User


Joined: 30 Oct 2003
Posts: 45
Location: Australia

PostPosted: Sun Apr 18, 2004 1:43 am    Post subject: Reply with quote

Hi all,

while upgrading to 1.1.1 I finally found the autosave feature: >Tools>Options>Load/Save>General

OOo now very politely asks me if I want to save every 15 minutes. I tell it yes, then run the time stamp macro as well... problem solved very neatly : )

I'm sure you have already looked into it, but is there possibly something in the AutoSave feature which would give you timer control? Just an idea, but since I know nothing about coding I'm probably talking through my hat...

Schelle
_________________
"Poetry is the journal of a sea animal living on land, wanting to fly in the air."
(Carl Sandberg)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group