|
|
|
November 1999: Displaying Macro Status for the User
There may be times when your macro needs to do a lot of work while the user waits. But if nothing is happening on the screen, the user may think that the computer is hung. There are a few methods you can use to let the user know that something is still going on.
Macro Status PromptA very simple method of displaying a status on screen is to use the MacroStatusPrompt. For example, the macro may be working its way down the document line by line, doing what it is supposed to do. A MacroStatusPrompt can display which line number the macro is currently working on. As the macro works its way down the document, the line number can be displayed on the status prompt.While (?RightCode <> 0 and ?RightChar <> 0) // do whatever the macro is supposed to do // the cursor must be moving towards the bottom of the // document, and should eventually get to the very // end of the document MacroStatusPrompt(on!; "Currently working on Line " + ?Line) Endwhile One drawback with using the MacroStatusPrompt is that the text that appears is small, and is often difficult for the user to see, since it is on the status bar at the bottom of the screen.
Please WaitYou may want to display a simple Please Wait message with a changing ellipse at the end to show that the macro is still working. Here is the sample code:
vMessage:="Please Wait "
DialogDefine("PleaseWait"; 50; 50; 130; 60; Percent!; vMessage)
DialogAddText("PleaseWait"; "Msg"; 25; 25; 100; 14; Left!; vMessage)
DialogShow("PleaseWait"; "WordPerfect"; CB)
// do some stuff here
PleaseWaitProgress(vMessage)
// do some stuff here
PleaseWaitProgress(vMessage)
// do some stuff here
PleaseWaitProgress(vMessage)
// do some stuff here
PleaseWaitProgress(vMessage)
// finish up
DialogDestroy("PleaseWait")
// the next step in the macro here
Quit
Label (CB)
Return
PROCEDURE PleaseWaitProgress(vMessage)
Wait(3)
vString:=vMessage + ". "
RegionSetWindowText("PleaseWait.Msg"; vString)
Wait(3)
vString:=vString + ". "
RegionSetWindowText("PleaseWait.Msg"; vString)
Wait(3)
vString:=vString + ". "
RegionSetWindowText("PleaseWait.Msg"; vString)
EndProc
The PleaseWaitProgress procedure is where the message on the dialog is changed to make the ellipse "move." You can call this routine as many times as you want to from within the working part of the macro. You need to have a callback to allow the message box to stay on the screen, but you'll notice that the callback (Label(CB)) doesn't actually do any processing. It just sends execution back to where it came from each time the callback is called.
The Progress BarBy far, the most sofisticated way to show the user that the macro is still working is to use a progress bar. A progress bar keeps the user informed as to what percentage of the work has been completed. The code below shows the basics of using a progress bar.
The tricky part is in changing the vPercent value to show a true approximation of the work that has actually been done. It may take trial and error to find the correct value to correspond with each portion of the processing code. Along with these three methods of showing progress, there can be several variations. You can often use the data that the macro is processing as part of the progress feedback, so the feedback solution for each macro application will vary.
Copyright Notice: The information included in the PerfectScript Journal is protected by US Copyright. The author grants you the right to use the routines in your own macros as needed. You may not sell, distribute, or publish them in any form.If you choose to use the information here, you do so entirely at your own risk. No representations are made regarding the fitness of this information for your particular purpose, or for your ability or inability to use the information. You are advised to make backups of all relevant files before implementing any suggestion or technique.© Copyright 1999 by J. Jeppson. |