Current Page:
NeXtMidas User's Guide
![]() ![]() ![]() |
|
Macro Example: triangle.mmThe following example ( 1: ! This computes some information about a right triangle. 2: ! 3: ! Parameters: 4: ! [angle] The measurement of one angle in Deg. 5: ! [lengthH] The length of the hypotenuse in mm. 6: ! 7: startmacro d:angle l:lengthH 8: calc l:lengthA lengthH angle sind * 9: calc l:lengthB lengthH angle cosd * 10: 11: res type "General Right Triangle" 12: 13: if angle EQ 45 then 14: res type "45 Deg. Right Triangle" 15: endif 16: 17: if angle EQ 60 OR angle EQ 30 then 18: res type "30-60 Right Triangle" 19: endif 20: 21: say "The given measurements define a ^type" 22: say "with sides that are ^lengthA mm and ^lengthB mm long." 23: endmacro Although it is significantly longer than the simple Lines 1 - 6: All lines beginning with an exclamation-point (also called a "bang") are comments and ignored by NeXtMidas. By using comments, a programmer explains the macro's function. Line 7: The
Lines 8 - 9:
These lines perform calculations using the values passed in. (See Line 11: This creates a results variable type. Although a macro can access the results set that exists in the environment in which it was called, it uses its own results set when setting results. Therefore, a macro will not accidentally overwrite results that belong to someone else and the results created by the macro are removed when the macro ends. To modify the results outside of
the current macro, use the switches provided by the Lines 13 -
15: Here is the first new command used inside a macro that is not
used at the command line. The Lines 17 -
19: This Lines 21 - 22: These lines print out information relevant to the user. Line 23: The macro ends with To run this macro, type the lines into a text editor and
save the file as nM> %mymacro 15 100 nM> %mymacro 30 100 nM> %mymacro 45 80 nM> %mymacro 30 "abc" After you complete each test, you should find that all of
the given values work except the last one ( |
|