19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

444 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

OCT If n is a whole number between 0 <strong>and</strong> 2,147,483,647, Oct(n) is the octal (that is, base<br />

8) representation of n.<br />

ON ERROR The statement On Error GoTo lineLabel sets up error-trapping. An error then<br />

causes a jump to the error-h<strong>and</strong>ling routine beginning with the first statement following the<br />

specified line label. The On Error statement <strong>and</strong> its target must be in the same procedure.<br />

[line label]<br />

ON . . . GOSUB <strong>and</strong> ON . . . GOTO The statement On expression GoSub lineLabel1, lineLabel2,<br />

. . . causes a GoSub to lineLabel1, lineLabel2, . . . depending on whether the value of<br />

the expression is 1, 2, .20.20.20. Similarly, the GoTo variation causes an unconditional jump<br />

to the appropriate line label. The GoSub or GoTo statement <strong>and</strong> its target must be in the same<br />

procedure. [line label]<br />

OPEN The statement Open “filespec”For mode As #n allows access to the file filespec in<br />

one of the following modes: Input (information can be read sequentially from the file), Output<br />

(a new file is created <strong>and</strong> information can be written sequentially to it), Append (information<br />

can be added sequentially to the end of a file), or Binary (information can be read or<br />

written in an arbitrary fashion). The statement Open “filespec”For R<strong>and</strong>om As #n Len = g<br />

allows r<strong>and</strong>om-access to the file filespec in which each record has length g. Throughout the<br />

program, the file is referred to by the reference number n (from 1 through 255). Another variation<br />

of the Open statement is Open “LPT1”For Output As #n, which allows access to the<br />

printer as if it were a sequential file.<br />

In a network environment, two enhancements to the Open statement are available. <strong>Visual</strong><br />

<strong>Basic</strong> accesses data files in two ways: it reads from them or writes to them. When several<br />

processes may utilize a file at the same time, accurate file h<strong>and</strong>ling requires that certain<br />

types of access be denied to anyone but the person who has opened the file. The statement<br />

Open “filespec”For mode Lock Read As #n or Open “filespec”For R<strong>and</strong>om Lock Read As #n<br />

Len = g opens the specified file <strong>and</strong> forbids any other process from reading the file as long<br />

as the file is open. Lock Write forbids any other process from writing to the file as long as<br />

the file is open. Lock Read Write forbids any other process from reading or writing to the<br />

file as long as the file is open. Lock Shared grants full access to any other process, except<br />

when a file is currently opened <strong>and</strong> locked by a process for a certain access mode, then<br />

another process attempting to open the file for the same mode will receive the message “Permission<br />

denied”<strong>and</strong> be denied access. [filespec] [binary file]<br />

OPTION BASE After the statement Option Base m is executed, where m is 0 or 1, a statement<br />

of the form Dim arrayName(n) defines an array with subscripts ranging from m to n.<br />

<strong>Visual</strong> <strong>Basic</strong>’s extended Dim statement, which permits both lower <strong>and</strong> upper subscript<br />

bounds to be specified for each array, achieves a wider range of results, making its use<br />

preferable to Option Base.<br />

OPTION COMPARE The statement Option Compare Text, placed in the (Declarations) section<br />

of (General), causes string comparisons to be case-insensitive. Thus, if Option Compare<br />

Text is in effect, the comparison “make”= “MaKe”will be true. The statement Option Compare<br />

Binary placed in the (Declarations) section produces the default comparison rules,<br />

which are case-sensitive <strong>and</strong> use the character order given in the ANSI/ASCII character<br />

tables.<br />

OPTION EXPLICIT If the statement Option Explicit appears in the (Declarations) section<br />

of (General), each variable must be declared before it is used. A variable is declared by<br />

appearing in a Const, Dim, Global, ReDim, or Static statement, or by appearing as a parameter<br />

in a Sub or Function definition.<br />

OR (Bitwise Operator) The expression byte1 Or byte2 is evaluated by expressing each byte<br />

as an 8-tuple binary number <strong>and</strong> then Oring together corresponding digits, where 1 Or 1, 1<br />

Or 0, <strong>and</strong> 0 Or 1 are all equal to 1, while 0 And 0 is equal to 0. For example, the expression<br />

37 Or 157 translated to binary 8-tuples becomes 00100101 Or 10011101. Oring together corresponding<br />

digits gives the binary 8-tuple 10111101 or decimal 189. Thus, 37 Or 157 is 189.

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

Saved successfully!

Ooh no, something went wrong!