11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Caché</strong> <strong>ObjectScript</strong> Special Variables$KEY set by the READ command or a SET command during a terminal session, you mustcopy the $KEY value to a local variable within the same line of code.ExamplesIn the following example, a variable-length READ command either receives data from theterminal or times out after 10 seconds. If the user inputs the data before the timeout, $KEYcontains the user-input carriage return (hex 0D) that terminated the data input. If, however,the READ timed out, $KEY contains the null string, indicating that no terminator characterwas received.READ "Ready or Not: ",x:10ZZDUMP $KEYIn the following example, a fixed-length READ command either receives data from the terminalor times out after 10 seconds. If the user inputs the specified number of characters (inthis case, one character), the user does not have to press to conclude the READoperation. The user can respond to the read prompt by pressing rather thanentering the specified number of characters.If the read operation timed out, both $KEY and $ZB contain the null string. If the user inputsa one-character middle initial, $KEY contains the null string, because the fixed-length READoperation concluded without a terminator character. If the user pressed ratherthan entering a middle initial, $KEY contains the user-input carriage return.READ "Middle initial: ",z#1:10IF $ASCII($ZB)=-1 {WRITE !,"The read timed out" }ELSEIF $ASCII($KEY)=-1 {WRITE !,"A character was entered" }ELSEIF $ASCII($KEY)=13 {WRITE !,"A line return was entered" }ELSE {WRITE !,"Unexpected result" }Notes$KEY and $ZB ComparedBoth $KEY and $ZB contain the character that terminates a READ operation. These twospecial variables are similar, but not identical. Here are the principal differences:• $KEY can be set using the SET command. $ZB cannot be SET.• Following a successful fixed-length READ, $ZB contains the final character input (forexample, when the 5-digit postal code “02138” is input as a fixed-length READ, $ZBcontains “8”). Following a successful fixed-length READ, $KEY contains the null string("").440 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!