Give ‘em a Practice Session
by Steve Workings
Originally published in Alpha Forum
Posted at www.workings.com January 20, 2001

A practice session. Wouldn’t that be great? A place where your users can learn and experiment without fear of making a mistake. A place where you or your client can debug the database or a new procedure without worrying about trashing good data.

Well, we all know how to make a practice session. That’s easy. Just copy everything from your production directory into a new directory, set a new shortcut to the practice files and you’re done. Right? Well...

I’ve added a couple features to my systems that the customers really love:

1. Make the Alpha Five window title reflect the fact you’re in a practice session.

2. Have each menu and submenu (and other selected forms) display the word "Practice."

3. Make a button for the user to easily update the practice session with all the current data.

Figure 1 shows the Main Menu of my current project as it displays in the production system. Figure 2 shows the same screen, but loaded from the practice directory. You’ll notice that the form in Figure 2 prominently displays the word "Practice" to help assure the users that they are indeed in the practice session. And the window title displays the word "Practice" many times.


Figure 1 - The Production Screen. This means you are not in the practice session.


Figure 1 - The Practice Screen. This means you are in the practice session.

As you will see, it takes just about a minute’s work to modify a form to display the special text. Though it’s really no big deal, the main drawback with this method is that you have to edit each form to display the text. But creating the different window title text is done once, and it displays all the time, whether the form has been modified for the practice text or not. I apply both methods to my systems -- I want the users to be sure and reassured that they’re in the practice session.

Here’s How To Do It

Attach the following Xbasic to the OnActivate event of the form that you automatically load when your database starts:

‘ Set global variable
‘ ------------------------
dim current_directory as c
dim global is_production_directory as l

‘ Get current directory name
‘ -----------------------------------
current_directory = a_db_current_path

‘ Set variable value depending on text in the directory name
‘ ---------------------------------------------------------------------------
if .not. ("A5DATA" $ ut(current_directory)) .and. .not.("ALLSTATE_FULL" $ ut(current_directory))
is_production_directory = .f.
practice_text.refresh()
end if

‘ Use global variable to select window title
‘ ----------------------------------------------------
if is_production_directory
:A5.window_title = "Allstate"
else
:A5.window_title = "Allstate - * PRACTICE * PRACTICE * PRACTICE * PRACTICE * PRACTICE * PRACTICE * PRACTICE *"
end if

You can easily read through the script above and understand what it does. A couple of explanations may be helpful, though.

I have a variable named current_directory, which gets its value from something called a_db_current_path. If you’re unfamiliar with this, take a couple more minutes and read up on page 36 of the Alpha Five Professional Edition manual. Alpha has a few system variables, such as a_db_current_path and a_field_value that can be very useful. In this case, a_db_current_path will return a value something like:

D:\A5DATA\

You’ll see that I set the is_production_directory variable to false if the directory is not one of two different choices. The reason for this is that my customer’s production directory is G:\A5DATA and my development directory is H:\ALLSTATE_FULL. I just don’t want the practice text showing up on my system.

If you’re not real familiar with the use of logical values in an expression, you may also be wondering a little bit about the syntax here. Why do I write:

if is_production_directory

instead of

if is_production_directory = .t.

Both methods will work just fine, but I find the first one a bit easier to read, write and debug because you don’t have to look for the periods (lack of or too many) surrounding the true condition. While we’re here, the measure of a false value can be written as:

if .not. is_production_directory

or

if is_production_directory = .f.

Edit The Forms

OK, if you’ve come this far, you’ll see the window title change reflected in your practice sessions. But you need to do just a bit of work to make any forms display the word "Practice." There are only two steps necessary to do this.

Pick the form that you want to use to display the text. As I mentioned above, it’s probably best to at least put the Practice text on your main menu. I also put it on all my submenus, and if I get really ambitious one day may add it to several other forms.

Put the form in design mode, and then do two things:

1) Make a calculated field called Practice_Text. The expression is:

IF (VAR->IS_PRODUCTION_DIRECTORY, "", "*PRACTICE*")

2) Drag and drop the new calculated field onto your form. As you can see by looking at Figure 1, I put the text in 20 point red italics. I also make sure that the text displays in the same place on each menu and submenu so the user gets used to it being there (or not being there!).

There is one more thing I like to do though strictly speaking it’s not necessary. I edit the form’s variable list and declare is_production_directory as a global logical variable on each form as well.

An Administrative Tool

A good practice session is one that’s up to date. It has yesterday’s or at least last week’s data and all the fixes and enhancements you’ve applied. But, it has to be copied over from the production directory to the practice directory on a regular basis. Sure, it’s easy enough to go to a DOS prompt or use Explorer to copy all the files from one directory to the other. But why not give the system administrator a button to do the job?

You’ll need a small batch file for this purpose -- put it in the production directory. I call my batch file PRACTICE.BAT, and it’s only one line long:

COPY *.* H:\A5PRACTICE

You’ll want to change the drive and directory reference to suit your situation.

Then, add a button in an appropriate place (I have a full console for many of my apps that’s only available to the system administrator) to run the batch file. The Xbasic behind that is only two lines long:

batname = A_db_CURRENT_PATH + "PRACTICE.BAT"
sys_shell(batname,1)

This will produce a DOS window so the user can see the files being copied. I haven’t found any good way to automatically close that window when it’s done but so far no one’s complained.

You could alternatively build this procedure entirely as an Xbasic script that doesn’t use a DOS batch file by using the Xbasic file_copy() command. If I was to do that, I’d also want to display a form that shows the files as they are copied. That’s why I chose the batch file and DOS window method -- they provide the scrolling file list with no extra work on my part. The Xbasic method, however, would also give you an easy way to ask the user for the name of the target directory for the new or updated practice session and perhaps apply other features.

What Else?

That’s it! If you do this or something like this, your users will become much better users of your system because you’ve given them a very safe place to experiment and learn.

You may also get some ideas of how you can make other things work differently depending on the value of the is_production_directory variable.

###