AUTHOR'S MAIN SITE  >>>  TABLE OF CONTENTS for Open Office database tutorials.  >>>  MACROS section, Open Office tutorials.
-d- Bookmark on Delicious    Recommend to StumbleUpon

Open Office Tutorials

File Management

Grandfather - Father - Son
Backup

This page is one of several trying to help you get the most out of the splendid Open Office. They are allied with a larger set concentrating on ooBase.

Remember that Open Office, including ooBase, is free! But don't let that fool you. And it's not new. Big organizations, government and civilian, are adopting it as their standard office suite... and saving million$, and still Getting The Job Done.

There's more about ooBase in the main index to this material.

This page is "browser friendly". Make your browser window as wide as you want it. The text will flow nicely for you. It is easier to read in a narrow window. With most browsers, pressing plus, minus or zero while the control key (ctrl) is held down will change the texts size. (Enlarge, reduce, restore to default, respectively.) (This is more fully explained, and there's another tip, at my Power Browsing page.)

Page contents © TK Boyd, Sheepdog Software ®, 2/06-11/11.



Introduction

This page is one of a group about using macros in Open Office. It gives you less help with basic macro work than some of the others do. It also has a very limited objective. If you are getting started with macros, or want more theory and less "just do this", then I'd suggest that you start with my Introduction to OOP, Events and Macros.

In this tutorial, you will be shown how you can set up a button that will do a type of backup for you. It was supposed to be something really simple, but, as ever, details emerged to make things tedious. The basic idea stayed simple. It was making the operations act upon the right directory that was tedious. That aspect of the button's action has been addressed at two levels.

This tutorial was written using ooBase version 3.0 on Windows XP, but many things should work the same way under other post version 1 OpenOffice installations, and under other operating systems. There are some strong reasons to move to Open Office 3.1 if you want to use macros with ooBase. Where the difference is important, you will be told.


Reviewing the situation....

Let's start by being clear about what a macro is. A macro is a recorded sequence of instructions. Anything you can do "by hand" (and more) can be put into a macro. If you have some tedious chore that you do over and over, you may want to consider creating a macro to simplify your life.

For instance, perhaps to guard against data loss you maintain three versions of some file. Let's say you keep the most current version in a file called "GoodStuff". And let's say that your next older version is called "GoodStuffDad", and the oldest version you have is called "GoodStuffGrandad".

From time to time, you....

Under such a scheme, from time to time, you will briefly have identical contents in "GoodStuffDad" and GoodStuff", but you are always in a position to get back to a recent version of the file, should something go horribly wrong while you have "GoodStuff" open for editing.

(This is, by the way, a monstrously complex system. It is a good system in some respects, especially if the backup copies are held on different storage devices, but it would want automating if you expected any human to operate it. Having said that... I do use a very similar system, by hand, for some of my files.)

If you wanted, you could do all of the above by hand... with all of the attendant chances for typos. Alternatively, you could create a macro, and turn the details of the chore over to your machine.... which is what we're going to do here. You may want to use our final result, but it is more likely to be mostly useful as an illustration of some programming techniques.


Let's go!....

First a bit of bad news: To keep things simple, for this tutorial you must work in your drive's root directory (aka folder, i.e. C:\). Also, the tutorial has a slight "Windows" flavor. But....

Getting past the "must work in root directory" problem is addressed in a subsequent tutorial, and....

The "Windows flavor" problem can be overcome by my fellow Linux enthusiasts, I think, by just one change. (Setting sPath to something else.)

So... caveats out of the way, onward....

Create, in your root directory (C:\) a simple text file called "Goodstuff.txt", and make copies of it (also in root) called "GoodStuffGrandad.txt" and "GoodStuffDad.txt"

Also in your root directory, create an ooWriter document called GFFS.odt (for "GrandFather/Father/Son"), put a button on it, link the button to a macro (stored in GFFS.odt) called RotateFiles which, for the moment, merely does....

MsgBox("This is just a start")

Second stage....

(Did you recognize the quote from the musical "Billy Elliot"? If you can get to one of the cities where it is playing, see it. It is excellent. Very faithful to the movie, with a whole extra dimension, due to the Elton John music and live performance.)

Back to work!

Here's what you need in order to accomplish what I've described. Note the rems in it, I won't repeat them all in the text of this tutorial.

I will stress two things by repeating them, though: The "Kill" command deletes a file without asking you if that's what you want. And the "Name" command (which might more helpfully have been called REname) replaces the contents of a file without seeking permission before acting.

The code below is slightly "inflated" by numerous MsgBox statements which are there so that you get explicit confirmation as the process proceeds.

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

Sub RotateFiles

Dim sGFFilename,sFFilename,sSFilename,_
   sPathToFile as string

sPathToFile="C:/"
sGFFilename="GoodStuffGrandfather.txt"
sFFilename="GoodStuffDad.txt"
sSFilename="GoodStuff.txt"

If FileExists(sPathToFile+sGFFilename) Then
  Kill(sPathToFile+sGFFilename)
  REM BEWARE: "Kill" will do just that to a file... with
  ' no "Are you sure?" confirmation step. And it won't
  ' be in the recycle bin, either.
  MsgBox("File "+sGFFilename+" deleted")
End If

If FileExists(sPathToFile+sFFilename) Then
  Name sPathToFile+sFFilename As sPathToFile+sGFFilename
     'The use of "As" in the previous has nothing to do with a Dim
     '... and yes, you do need to specify the path for both
  REM BEWARE: If file is open in another OO window, you'll get
  '  a message saying "File not found".... not the most helpful
  '  error message!
  'It would be nice if I could discover an "Is it open?" test,
  '  to use as the FileExists test was used. Sigh.
  MsgBox("File "+sGFilename+" copied to make new "+sGFFilename)
  Else
  MsgBox("There was no '"+_
     sFFilename+"' to make new '"+sGFFilename+"' from")
     'You can't, by the way, put a split inside an
     'explicit string. Won't work:
     '   MsgBox("Split in _
     '       string.")
     'But will work:
     '   MsgBox("Split in "+_
     '       "string.")
End If

If FileExists(sPathToFile+sSFilename) Then
  FileCopy (sPathToFile+sSFilename, sPathToFile+sFFilename)
  MsgBox("File "+sSFilename+" copied, overwriting old "+sFFilename)
  Else
  MsgBox("There was no '"+_
     sSFilename+"' to make new '"+sFFilename+"' from")
End If

MsgBox("File Grandfather/Father/Son job done.")

End Sub

The macro will have problems if you run it before you have "GoodStuff.txt" and "GoodStuffDad.txt" files on the disc. This could be taken care of easily enough... exercise for the student... but I didn't want to clutter the code with "details".


We've done it!...

That's about it, for this tutorial. How you can refine the above so that it works someplace other than in the root directory is addressed in my tutorial on document properties.

I hope the above will incline you to return to the main page of my Open Office tutorials, and access other tutorials.



Editorial Philosophy

I dislike 'fancy' websites with more concern for a flashy appearance than for good content. For a pretty picture, I can go to an art gallery. Of course, an attractive site WITH content deserves praise... as long as that pretty face doesn't cost download time. In any case....

I am trying to present this material in a format which makes it easy for you to USE it. There are two aspects to that: The way it is split up, and the way it is posted. See the main index to this material for more information about the way it is split up, and the way it is posted.


Ad from page's editor: Yes.. I do enjoy compiling these things for you... I hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!

PLEASE >>> Click here to visit editor's Sheepdog Software (tm) freeware, shareware pages <<< PLEASE


If you liked this ooBase tutorial, see the main index for information other help from the same author.

Editor's email address. Suggestions welcomed!     - - -    Want a site hosted, or email? I like 1&1's services.




Valid HTML 4.01 Transitional Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org


One last bit of advice: Be sure you know all you need to about spyware.

. . . . . P a g e . . . E n d s . . . . .