OCLC Macro Language for the complete beginner!


by Joel Hahn

If you're intimidated by the thought of editing or even (gasp!) writing your own OCLC macros, here's one place to start to pick up some of the essentials of programming with OML. Writing your own macros can be quite rewarding and even--dare I say--fun, once you get a handle on a few basic concepts and commands.

(Disclaimer/note: For the purposes of teaching the rudiments, I may leave out some details that don't impact much on the concept at hand but might be very important for intermediate or advanced programming. You have to learn to add before you can learn that repeated adding is the same as multiplying.)

Ok. You've finally gotten up the gumption to press that ol' Create button. You're faced with a barrage of windows demanding immediate responses (but, luckily, explaining themselves fairly well) and then finally a mostly-empty screen.

  ' MacroName: [the name you entered before clicking Create]
  ' MacroDescription: [the brief description of what the macro does, which
  '                   you entered in one of the windows that appeared.]
  sub main

  end sub

Quickie translation:

"MacroName" and "MacroDescription" are self-explanatory. You can change them all you want from this screen, but that won't have any impact on what displays elsewhere in PfW (such as the Macro window or the Customize... window). There are ways to get different names and descriptions, so don't panic if you don't like what you typed!

"Sub main" and "end sub" are the core of the macro. They tell the computer that everything between those two commands is the heart of the program. In essense, when the macro runs, it starts at "sub main" and runs until it hits "end sub," at which point it stops and the stopsign button on the main window goes blank again.

The first character in each of the first two lines is also important to learn right off the bat. A "remark" is a note from the programmer to whomever reads the program next; REM is not just a rock group, it is a command that tells the computer to ignore everything following the REM on the current line. A synonym for REM is the single quote mark ('); that is what is most commonly used for remarks in OML. Also, the verb phrase "to comment out" means "place a ' or a REM at the front of the line"; you will often see this in macros with instructions on how to customize them for your own uses.


Here's a little trick that will make your life a lot easier when writing macros. It's so useful for OML macros that even the Macro Recorder automatically includes it!

  Dim CS as Session
  Set CS=CurrentSession

Translation:

1) "Create a short-hand method of referring to a Passport session, and use 'CS' as the short-hand for that."
2) "CS is short-hand for whichever session is currently open & active when the macro is run."

Now, instead of typing out "CurrentSession" in commands like "CurrentSession.Send" or "CurrentSession.PutText" (don't worry, I'll explain what the commands in a minute), you only have to type "CS.Send" and "CS.PutText."

(Other than that, it's not all that important at this point that you understand exactly how these commands work, as long as you grasp the basic concept of creating the short-hand so that "CS" works wherever you'd normally put "CurrentSession".)

CS.Send and CS.PutText (see how handy that is?) are commands you'll find yourself using a lot, especially at first as you start to get your feet wet with writing macros. Send is used mostly for non-OCLC sessions, and PutText is used mostly for OCLC sessions. PutText is only used in Block sessions, like all OCLC sessions.

Send means "Send this text to the computer at the other end of the active session." (Even though it's the same word, this is not the same as OCLC's "Send" commands--the F10 and F11 that you are used to.) For example, here is a macro that can be used to respond to the common system request "Press any key to continue":

  sub main
    CurrentSession.Send "a"
  end sub

What this macro does is send the character "a" as if the user had typed it. (You can now take that macro, map it to the F1 key, take the "F1" label off of the key and replace it with a label marked "Any", as an answer to the perennial new-user question "Where's the Any key on this keyboard?")

The following use of Send may be more familiar, especially if you've ever looked at an OCLC Logon macro. (Note that this shouldn't be run as is; there are a lot of other necessary commands missing.)

  sub main
    CurrentSession.Send "c prism*j\e"
  end sub

PutText is similar, but instead of sending a character to the session, it merely finds a spot on the screen and puts some text there. Here's a quick example:

  sub main
    CurrentSession.PutText "PDN"
  end sub

This macro finds the cursor's current location, and prints the text "PDN" there. It doesn't actually send anything to the computer at the other end of the session, it just makes those characters appear on the screen. In the context of OCLC, it is as if you typed the text yourself, but you would still need to press F11 as normal to send the text.

If you wanted that last macro to send the PageDown command for you, you'd need to include that F11 somehow, right? Since with the arrival of Passport for Windows, all of OCLC's commands are now macros, what you actually need to do is tell your macro to run OCLC's 'Send Command' macro.

  sub main
    CurrentSession.PutText "PDN", 1, 1, NORMAL
    RunMacro "PRSMUTIL!SendCommand"
  end sub
And if you open up the "PageDown" macro, you'll see that's exactly what it does!

"Wait a minute," I hear you cry, "what about those other parts in the PutText command?" Those are optional parts of the command. The word indicates the "attribute" that the text will have; example attributes are NORMAL, REVERSE, and BLINK. (Upper- or lowercase doesn't matter--the computer will figure out what you mean. Common practice is to put it in all caps so that it's easier to spot.) The numbers tell the computer where on the screen to put the text. Since the first example wanted the text to go wherever the cursor was when the macro was executed, they weren't needed. Now, the text has to be in exactly the right place; in this case the upper left corner. The first number is the row and the second is the column. The numbering starts from the upper left corner; thus, "1, 1" is the first row and the first column. "13, 5" would mean "go down to the 13th row and then start at the 5th character in from the left." If you don't mind the defaults (current cursor location and NORMAL), you can leave either or both out.

As you could probably figure out, RunMacro tells the computer to run another macro. The second part of the command is the macrobook which contains the macro, an exclamation point, and then the name of the macro to run; all enclosed in quotes with no spaces. In this case, the computer goes into the PRSMUTIL macrobook (where most of the pre-made PrismCat macros are), and runs the SendCommand macro; this has the same result as a user pressing F11 (due to that macro being normally assigned to F11).

Because of the way Passport handles macros, the macro runs faster if you include the above two lines in order to page down, rather than just including 'RunMacro "PRSMUTIL!PageDown"' (which is usually assigned to F4) You can just do that, but it means the computer will have to load and translate three macros into a language it understands (1. the one you're running, 2. the PageDown macro, and 3. the SendCommand macro that is used by the PageDown macro); this understandably slows things down a bit and uses up more RAM than normal.

You now can create macros that will handle most simple tasks with a single command from the user. Possible examples are "val", "xpo", "u", "delh", and even multiple commands, such as "val [and then] s."

Next time, variables...


Return to Main page.