Give em a Practice
Session
by Steve Workings
Originally published in Alpha Forum
Posted at www.workings.com
January 20, 2001
A practice session. Wouldnt 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. Thats easy. Just copy everything from your production directory into a new directory, set a new shortcut to the practice files and youre done. Right? Well...
Ive added a couple features to my systems that the customers really love:
1. Make the Alpha Five window title reflect the fact youre 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. Youll 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 minutes work to modify a form to display the special text. Though its 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 theyre in the practice session.
Heres 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 youre 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\
Youll 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 customers production directory is G:\A5DATA and my development directory is H:\ALLSTATE_FULL. I just dont want the practice text showing up on my system.
If youre 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 dont have to look for the periods (lack of or too many) surrounding the true condition. While were 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 youve come this far, youll 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, its 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 its not necessary. I edit the forms 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 thats up to date. It has yesterdays or at least last weeks data and all the fixes and enhancements youve applied. But, it has to be copied over from the production directory to the practice directory on a regular basis. Sure, its 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?
Youll need a small batch file for this purpose -- put it in the production directory. I call my batch file PRACTICE.BAT, and its only one line long:
COPY *.* H:\A5PRACTICE
Youll 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 thats 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 havent found any good way to automatically close that window when its done but so far no ones complained.
You could alternatively build this procedure entirely as an Xbasic script that doesnt use a DOS batch file by using the Xbasic file_copy() command. If I was to do that, Id also want to display a form that shows the files as they are copied. Thats 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?
Thats it! If you do this or something like this, your users will become much better users of your system because youve 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.
###