home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / lotus123 / lotushlp.arc / LOTUS4.DOC < prev    next >
Text File  |  1985-05-31  |  8KB  |  199 lines

  1.  
  2.  
  3.  
  4.                                 1-2-3 Macro Tips
  5.                                  Looping Macros
  6.  
  7.         This  short  article outlines several practical uses  for  macros 
  8.         which  loop,  or  repeat tasks,  until the user chooses  to  stop 
  9.         performing an operation.
  10.  
  11.         Simplifying Use of Numeric Keypad
  12.  
  13.         This macro allows you to use the numeric keypad at the right side 
  14.         of  the  keyboard.  Of course,  you can always use the keypad  by 
  15.         pressing the [Num Lock] key,  or by holding down the [Shift]  key 
  16.         while  typing the numbers on the pad.  Unfortunately,  the cursor 
  17.         motion  keys are on the same pad,  and you usually move the  cell 
  18.         pointer after typing each number.
  19.  
  20.         This macro takes care of moving the cell pointer,  so it is named 
  21.         \M, for Move. While using it, you should leave the [Num Lock] on. 
  22.         The NUM indicator in the lower right-hand corner of the screen is 
  23.         displayed when the numeric keypad is set for the input of numbers 
  24.         only.
  25.  
  26.         The  Move Macro takes advantage of the special macro  instruction 
  27.         {?}. This stops execution of the macro and gives control of 1-2-3 
  28.         back to you. The macro resumes when you press [Enter]. 1-2-3 lets 
  29.         you  know  that  you are still in a macro by displaying  the  CMD 
  30.         indicator  next  to the Mode indicator in  the  upper  right-hand 
  31.         corner of the screen.
  32.  
  33.         The Move Macro waits until you make an entry,  and moves the cell 
  34.         pointer  when you press [Enter].  For this example the macro will 
  35.         move  the cell pointer down,  but it could be written to move  it 
  36.         laterally or diagonally. Without looping, it consists of just two 
  37.         instructions:
  38.  
  39.           Range Name     Command     Comments
  40.                \M          {?}       Wait until [Enter].
  41.                          {down}      Move the cell pointer down.
  42.  
  43.         When you press Alt-M, the CMD indicator is displayed, but nothing 
  44.         else  happens because the first instruction is to wait.  Type  an 
  45.         entry,  press [Enter], and the cell pointer will move down. Since 
  46.         you don't need a cursor key,  you could leave the [Num Lock]  on. 
  47.         So  far,  however,  this  is not very helpful since typing  Alt-M 
  48.         before each entry is more bother than any of the alternatives.
  49.  
  50.         Creating a Looping Macro
  51.  
  52.         The  solution is the loop.  To make the macro repeat  itself,  an 
  53.         "invisible"  X  command in the 1-2-3 top level command menu  (the 
  54.         one that begins "Worksheet...Range...") must be used. /X commands 
  55.         may only be used in macros.  1-2-3 commands are written in macros 
  56.         as a slash (/) followed by one or more letters.  The /X  commands 
  57.         consist  of /X followed by one letter.  For example,  /XQ quits a 
  58.         macro  and /XM puts up the command menu.  /XG is the  macro  Goto 
  59.  
  60.  
  61.                                         1
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.         command that may be used to make a macro loop. (By the way, don't 
  71.         confuse /XG with the F5 {goto} key, which moves the cell pointer, 
  72.         and which can also be used in macros.)
  73.  
  74.         The  /XG  command tells 1-2-3 to get its next  macro  instruction 
  75.         from somewhere other than the rest of the label or the next label 
  76.         cell  down,  as  it normally would.  After the G,  enter  a  cell 
  77.         coordinate or range name, to tell 1-2-3 where to get its next set 
  78.         of instructions.  Enter a tilde (~) after the coordinate or range 
  79.         name.
  80.  
  81.         HINT:  Using  range names is better than using  cell  coordinates 
  82.                because  it  will  insure  that the  macro  will  function 
  83.                correctly when you /Move cells,  or /Worksheet Insert  and 
  84.                Delete Rows and Columns.  Assign range names to individual 
  85.                cells  containing  macro commands.  To keep things  clear, 
  86.                place the range names as labels in the column to the  left 
  87.                of  the macro instructions,  and use the /Range Name Label 
  88.                Right  command  to assign them to the first step  of  each 
  89.                macro  routine.  If a named range contains more  than  one 
  90.                cell, the /XG command will begin execution at the top left 
  91.                corner of the range.
  92.  
  93.         In  this  case,  it would be preferable for the entire  macro  to 
  94.         repeat,  and it already has a range name,  \M.  To make the macro 
  95.         repeat,  just  type  this  label  in  the  cell  below  the  cell 
  96.         containing {down}:
  97.  
  98.              /XG\M~     Go back to the beginning of the macro.
  99.  
  100.         After the macro has moved the cell pointer down,  it performs the 
  101.         instruction in the next cell in the macro. This instruction tells 
  102.         1-2-3 to go back to the start of the macro,  where it again waits 
  103.         until you press [Enter],  moves the cell pointer down,  repeating 
  104.         indefinitely.
  105.  
  106.         Stopping This Macro
  107.  
  108.         Now  that  an endless loop has been established,  how can  it  be 
  109.         stopped? The best method is to hold down the [Ctrl] key and press 
  110.         [Scroll-Lock/Break].  When  you see ERROR in the Mode  Indicator, 
  111.         don't  worry.  Press [Enter],  [Esc],  or [Ctrl-Break] again  and 
  112.         everything  will  be  fine.  This  method can  be  used  to  stop 
  113.         execution  of any macro,  a printing operation,  or a long  /Data 
  114.         Table  calculation.  Before you [Ctrl-Break] out of  this  macro, 
  115.         however, consider entering another column of numbers. While 1-2-3 
  116.         is  waiting  (the  CMD indicator is on),  you may move  the  cell 
  117.         pointer.  Just  turn  off  the [Num-Lock] or  press  shift  while 
  118.         pressing  the  cursor keys.  Otherwise,  you'll get a  string  of 
  119.         digits typed in the current cell.
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.                                         2
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.         Clarifying the Meaning of Tilde (~)
  137.  
  138.         You  may have some lingering questions about the when's and why's 
  139.         of  the  tilde.  To  further  illustrate  its  use,  examine  the 
  140.         following macro.  It moves down a column of labels,  editing each 
  141.         one and stopping to allow you to add to the existing label.
  142.  
  143.           \E  {edit}{?}~    Edit the label and wait for [Enter].
  144.               {down}        Move the cell pointer down.
  145.               /XG\E~        Repeat the macro from the beginning.
  146.  
  147.         There  are only two differences between this macro and  the  Move 
  148.         Macro.  The  {edit} key is obvious.  But why the tilde after  the 
  149.         {?};  you  have to press [Enter] to resume the macro anyway.  The 
  150.         answer is that the {?} "swallows" the [Enter];  it is never  sent 
  151.         to 1-2-3. To exit Edit mode, you must press [Enter]. This is done 
  152.         by  the  macro when it reads the tilde.  In the  Move  Macro,  no 
  153.         [Enter]  was  needed  and,  just as none is needed when  you  are 
  154.         entering values or labels, no tilde is required after the {?}.
  155.  
  156.         {?} as a Breakpoint
  157.  
  158.         If you're setting out to do more extensive macro programming, one 
  159.         more  hint  is  in  order.  The  {?}  wait  instruction  is  what 
  160.         programmers call a "breakpoint." It stops everything and lets you 
  161.         examine your work.  If you've written a large macro and it's  not 
  162.         doing  what you think it should,  put breakpoints at the ends  of 
  163.         several of your macro labels. Then, when execution stops, you can 
  164.         look around the spreadsheet to see if, so far, things are as they 
  165.         should be.
  166.  
  167.         In Summary
  168.  
  169.         The  pointer  movement was entered into three cells in a  column, 
  170.         but could be stored in any number of ways.  If you use it a  lot, 
  171.         you might want to put it in one line:
  172.  
  173.         \M  {?}{down}/XG\M~    Wait, move down and repeat.
  174.  
  175.         The  Move Macro is handy;  it could be tremendously helpful  when 
  176.         entering a large amount of numeric data.
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.                                         3
  194.  
  195.  
  196.  
  197.  
  198.  
  199.