Previous Next         Current Page: NeXtMidas Training / Macros - Part 1 (Basics) / Lab 3 / Instructions
Start Here   
Background   
Common Midas Concepts   
Getting Started   
Working with Files   
Option Trees   
Macros - Part 1 (Basics)   
   + Macro Basics   
   + Lab 1   
   + Lab 2   
   + Loops and Control Structures   
   - Lab 3   
      - Instructions   
      - Solution   
   + Lab 4*   
   + Procedures and Subroutines   
   + Lab 5   
   + Lab 6*   
   + Pipes in a Macro   
   + Lab 7   
   + Lab 8   
   + Messages in a Macro   
   + Lab 9   
   + Lab 10   
Macros - Part 2 (Graphics)   
Primitives   
Installing NeXtMidas   
Applets & WebStart   
Mapping (NeXtEarth)   
Remote Midas InterFace (RMIF)   
Using NetBeans   
X-Midas Interoperability   
Remoting an X-Midas App.   


  • Lab 3:
    • Using a text editor, create a new file named mcrlab3.mm in the mcr area of the TRAIN option tree (this is the option tree you created in Lab 2).
    • Your macro will take in one parameter TAB= which will be a table.
    • Inside the body of the macro will be three loops:
      Loop 1:
      Create a counting loop that counts by-threes from -9 to 9.
      Inside this loop you will need to add a conditional that has three blocks in it (IF, ELSEIF, and ELSE).
      Your conditional should check to see if the current count is zero, even or odd and should print out an message telling the current count and whether it is zero, odd or even.
      Hint: Before the IF you can use CALCULATOR to compute x = (count mod 2); by doing this you will know if the count is even (x=0) or odd (x=1).
      Loop 2:
      This loop is more complicated than the first loop and will require a little bit of code before the loop to set things up.
      In this loop you will be asked to convert between nautical miles (nmi) and kilometers (km). So the first thing you need to do is set up the conversion factor (NM2KM).
      • NeXtMidas already has the conversion from nautical miles to meters in its set of constants. You will need to use INVOKE to get the value of nxm.sys.inc.Constants.NM2METERS.
      • Once you have the value of NM2METERS you can use calculator to convert this to NM2KM (if you remember back to high school, you will recall that there are 1000 meters in a kilometer, so this is just a simple division using CALCULATOR).
      Starting with 0nmi you will need to print out the conversion of nautical miles (nmi) to kilometers (km) for all integer values of nmi where km is less than ten.
      Hint: You can initially start with 0nmi=0km.
      Loop 3:
      This is an easy loop.
      Just loop through the keys in the table that was passed in and print out the key and the value it corresponds with.
    • When you are done use UPDATE to add your macro to the dictionary and try it out. The output should look similar to this:
      nM> mcrlab3 {A=1,B=2,C=3}
      Count is -9 (odd)
      Count is -6 (even)
      Count is -3 (odd)
      Count is 0 (zero)
      Count is 3 (odd)
      Count is 6 (even)
      Count is 9 (odd)
      0nmi = 0.0km
      1nmi = 1.852km
      2nmi = 3.704km
      3nmi = 5.556km
      4nmi = 7.408km
      5nmi = 9.26km
      6nmi = 11.112km
      KEY=A VALUE=1
      KEY=B VALUE=2
      KEY=C VALUE=3