OML for the complete beginner, #6

Normalized data

As you have probably already seen if you've browsed the OML help file, some commands that use strings require that input be given as "normalized data". This can be pretty confusing until you get the hang of it, as well as remember which commands require it and which don't. This is generally used in CatME only if you use it to telnet to somewhere other than OCLC, but it is still something you should know for those times when it does come up.

Normalized data is a way of expressing strange characters or simple commands with the standard symbols, letters, and numbers found on your average typewriter keyboard. It starts with a backslash, then a letter, and sometimes also a number.

There are two normalized combinations that are used most often; these are "\r", the equivalent of hitting the Return key, and "\x", a character string, roughly equivalent to Chr$.

The first one, "\r", is used whenever you want to include a Carriage Return (a.k.a. "pressing Return") in a string. This is probably most often used in Logon scripts. A few systems may also (or instead) require a line feed, which is represented by "\n"

The second, "\x", indicates that the next two characters are the hexadecimal (base-16) ASCII code for a character. (These are not visually the same as the decimal ASCII codes, though they have the same value.) Of these, the most commonly used are probably \x09 (Tab) and \x1B (Escape), though any character--including the special ALA characters--can be inserted in this manner. (OML also supposedly includes "\t" for Tab, but I find that it doesn't work like it should; \x09 definitely works.) Note that case doesn't matter in this command; \x1b is the same as \x1B. For the sake of reference, \x09 in normalized data is the same as Chr(9) in standard data, and \x1B in normalized data is the same as Chr(27) in standard data.


Most computer textbooks include an ASCII table listing both the decimal and hexadecimal codes for each character from 0-127 (decimal) and 00-7F (hexadecimal). The extended ASCII characters, which is where OCLC has put all of the ALA diacritics and other special characters, can be accessed in Windows 95 through the Character Map (Start/Programs/Accessories/Character Map); click on one of the special characters, and the decimal equivalent will be displayed. To convert from decimal to hexidecimal notation, divide by 16. Take the number to the left of the decimal point as the first digit; if it is higher than 9, convert it to a single digit by following the pattern 10 = A, 11 = B... 15 = F. Now multiply the fraction to the right of the decimal point by 16 and make the result the second digit; converting to A-F if necessary.


Knowing the combination for Escape can be handy, as it then allows for "escape codes"; this the main method for inserting arrow keys, function keys, and Control-[letter] commands into a macro. This is not necessarily all that useful for OCLC work (both cursor movement and function key commands are much more easily achieved by using other commands), but invaluable when using CatME to telnet elsewhere.

Discovering the codes for arrow and function keys is not as easy in CatME as it is in Passport, however, because CatME does not include a macro recorder. Some trial and error will probably be necessary, but the arrow keys will be \x1B (or Chr(27)) plus [A (Up), [B (Down), [C (Right), and [D (Left). The codes for function keys may vary from system to system, but a good starting point is to try \x01 (or Chr(1)) and add A for F1, B for F2, C for F3, a for Shift-F1, b for Shift-F2, and c for Shift-F3. (Yes, upper case letters are used for the normal function keys and lower case for Shift plus a function key.)

If you want to include characters in a normalized string that are usually used as part of the normalization or the string definition--that is, double-quotation marks and backslashes, you do not have to use a hexadecimal workaround (though that will also work); these characters have their own normalizations, which are gotten simply by putting a backslash immediately in front of them. That is, "\"" is a double-quote, and "\\" is a backslash.

As far as using normalized data goes, it's just a matter of including it in a string. For example, here's a rudimentary logon macro for a typical VT100 telnet session. (Note that this uses the "CatME.Terminal" object instead of the "CatME.Application" object; CatME.Application is used for commands inside of CatME, CatME.Communications is used for commands that act on the connection between CatME and a computer you connect to via phone line or telnet, including OCLC, and CatME.Terminal is used for commands which act on a telnet session to a computer other than OCLC, such as your local catalog. Since the use of the Terminal object is a more advanced technique, it is beyond the scope of this lesson; this example is thus included solely to illustrate the actual use of normalized data.)

  sub main
    Dim CS as Object
    Set CS = CreateObject("CatME.Terminal")
    CS.Receive, 10, "Logon:"
    CS.Send "username\r"
    CS.Receive, 10, "Password:"
    pass$ = "mypass\r"
    CS.Send pass$
  end sub

This macro waits for the indicated text, then sends the logon or password, followed immediately by the Return key. Note that the normalized text must be inside the quotation marks. The other end receives each character as if it were typed by the user, including the Return key at the end, and handles it normally. For the password, this example shows one way of using string variables to achieve the same end. Note that some people may find it easier if you use "mypass" & "\r" instead of the example above; this way, one can better tell where the regular data ends and the special characters begin. This can be especially important when the normalized data is in the middle of a string. For example, here are two ways of presenting the same data:

   a$ = "\xDC\x0910 100 1\x09\xDFa Twain, Mark."

   b$ = "\xDC\x09" & "10 100 1" & "\x09"
   b$ = b$ & \xDF" & "a Twain, Mark."

There are a few extended ASCII characters in there (in OCLC terms, delimiters or diacritics), as well as a couple of tabs. The first example is a jumble of characters, though it's not too difficult to eventually puzzle it out by watching the slashes. The second clearly delineates between the normalized special characters/commands and the plain text.


As for using normalized data versus standard data (such as Chr(27)) for commands that accept either one, here is the same basic data as above, but presented using standard instead of normalized data.

   a$ = Chr(220) & Chr(9) & "10 100 1" & Chr(9) & Chr(223) & "a Twain, Mark."

As you can see, it is even easier to tell the special characters apart from everything else than in either example above.

Next time, loops...


Return to Lesson #5.
Return to Main page.