#: 137038 S2/WordStar 7/6 Editor
    26-Oct-92  08:36:35
Sb: #137022-7C Questions
Fm: John G. Bennett 72431,1407
To: George Geiger 72416,2400 (X)

George,

Let me try to give you some general purpose advice about making macros repeat.

To make a portion of a macro repeat, you make it a loop.  To do that, you need
to insert a label at the beginning of the portion you want to have repeat and
at the end you put in a GoTo followed by the label.  For instance, like this:

  Sub Main
      AutoRestore(ON)
      SetHelpLevel(2)
      Insert(ON)
      CmdTags(ON)
      HideDots(OFF)
      ColMode(OFF)
      ColReplace(OFF)
  Start: Key("^Qg{Tab}")
      Key("{Del}^P.")
      GoTo Start
  End Sub

This macro replaces all of the tabs in your document by dot leader tabs.  The
label "Start" marks the beginning of the part of the macro you want to repeat. 
When the macro comes to the GoTo statement, it goes to the label and continues
from there.  You wouldn't want to run that macro as it stands, because it
wouldn't stop.  (You could stop it with the Escape key, if you haven't set that
up for something else.)

 [More]


#: 137039 S2/WordStar 7/6 Editor
    26-Oct-92  08:36:52
Sb: #137022-#7C Questions
Fm: John G. Bennett 72431,1407
To: George Geiger 72416,2400 (X)

 [Continued]

To make macros stop, you must use the exception processing mechanism. Whenever
a command is halted to put up a dialogue or to tell you something went wrong,
that's an Exception.  You can do something appropriate at that point by using
the IfExeption command.  Read about this in your reference manual on pp. 12-38
to 12-41.  For instance, our macro above can be made to stop at the end of the
file (provided the file doesn't end with a tab) by making it look like this:

   Sub Main
       AutoRestore(ON)
       SetHelpLevel(2)
       Insert(ON)
       CmdTags(ON)
       HideDots(OFF)
       ColMode(OFF)
       ColReplace(OFF)
   Start: Key("^Qg{Tab}")
         IfException
         ACK: Key("{Enter}")
              Stop
         End IfException
       Key("{Del}^P.")
       GoTo Start
   End Sub

Here's a tip.  Macros are much easier if you can record them.  If you record a
macro like the one above with your cursor near but not at the end of the file,
you can record the IfException clause, too.   (You mustn't be at the end of the
file, for a search started there doesn't generate an exception.  You want to be
past the last item in the file you are searching for.)  Then all you need to do
in the editor is to insert the label and the GoTo statement, and put a Stop in
the exception clause.  (You can write macros to do that, if you feel
ambitious!).

If this isn't enough help, please ask again, telling us what you want to do
with your repeating macro.

-jgb


#: 137134 S2/WordStar 7/6 Editor
    27-Oct-92  10:14:27
Sb: #137022-#7C Questions
Fm: James Burton (WSI\Sysop) 76702,334
To: George Geiger 72416,2400 (X)

1. It doesn't work exactly that way.  The filename stack will retain the name
of the second file *unless* you save the first file.  Then the second filename
will be flushed.  I don't know of any way to change it.

2. Sorry to say I don't know of a way to supress directory names in the file
directory, either.

3. WordStar only supports Extended under XMS.  Make sure you have HIMEM.SYS or
equivalent loaded.  Also make sure that something like SMARTDRV isn't grabbing
it automatically.

4. This macro file is a good example of a looping macro:

 Sub Main
    AutoRestore(ON)                     'Restore setting when macro finished.
    WSQuiet(ON)                         'Supress dialog display.
 Begin:
    Key("{Ctrl+Q}{Ctrl+F}")             'Find Tab.
    Key("{Ctrl+P}{Ctrl+I}{Enter}")
    Key("{Enter}")
       IfException
       ACK: Key("{Enter}")              'If no Tab found, stop macro.
         GoTo Bye
       NCM: GoTo Bye                    'If End of File reached, stop macro.
       End IfException
    Key("{Ctrl+G}{Ctrl+P}.")            'Delete Tab, type Dot Leader Tab.
  GoTo Begin                            'Repeat (until exception encountered).
  Bye:
 End Sub
