One of the main advantages of using BASIC is that it makes entering, editing, and storing programs a simple task. This chapter introduces you to the concepts and skills involved in entering and storing BASIC programs.
Knowing the following terms will help you learn how to edit and store programs:
keyword | A group of characters recognized by BASIC to represent some pre-defined action, such as CAT, LOAD, and COPY. | |
statement | A keyword followed by any parameters and/or secondary keywords that are
required or allowed with that keyword, and fit on one program line.
The maximum length of a command or program line is two CRT lines (up to 256 characters). On most models, this is 160 characters when you enter lines from the keyboard, but only 100 characters on the Model 226. You can create program lines longer than 100 characters on a 310, for instance, and then transfer them to a 226 using a mass storage operation such as LOAD or GET. The resulting program lines are valid on the 226, but, when viewed on the CRT in EDIT mode, these lines have an asterisk after the line number, with only the first 100 characters visible. Examples of statements are:
|
|
command | A statement that is executed from the keyboard. | |
program line | A statement preceded by a line number (and optional line label) that
is stored in a program. Examples are:
|
In general, a statement can be used as either a command or program line:
PRINT "This is a keyboard command." [Return]
100 PRINT "This is a program line."
However, there are some statements that cannot be executed as commands (such as DIM and RETURN):
100 DIM String_var$[100]
or stored as program lines (such as DEL and SCRATCH):
SCRATCH A
The HP BASIC 6.2 Language Reference indicates whether or not a keyword is keyboard executable, programmable, or both.
You can enter a program by typing program lines (line number and statement) on the normal keyboard input line of the CRT and pressing [Return]. But it is usually better to use EDIT mode because you can see several program lines at one time, and the BASIC editor checks the syntax of each line as you enter it.
NOTE |
---|
Note The EDIT binary must be loaded in order to use the editor. |
To enter the editor using an ITF keyboard:
EDIT [Return]
or
(On an HP 98203B/C keyboard, press [EDIT], then [EXECUTE]. On an HP 98203A keyboard type EDIT followed by [EXEC].)
The EDIT screen has this format:
110 A=.03
120 B=.02
130 X=0
140 Y=0
150 C=A+B
160 PRINT " Item Total Total"
170 PRINT " Price Tax Cost"
180 PRINT "-----------------------"
190 P=0 Current Program Line (2 CRT lines)
System Message Line (if needed)
Following Program Lines (if any)
200 INPUT "Input item price",P
210 D=P*C
220 E=P=D
230 X=X=D
240 Y=Y=E
250 DISP "Tax =";D; "Item cost =";E
260 PRINT P,X,Y
270 GOTO 190
280 END
User 1 Caps Idle
In this mode, you can view a multi-line portion of the program. You can view different portions of the program by scrolling the display (see subsequent section called "Keys Used for Scrolling the Program" for details). To edit a particular line, scroll the display so the line you want to edit is in the middle of the screen.
If there is no program in memory when you enter EDIT mode, the cursor will appear on a line with the number 10, the default line number for the first program line.
The EDIT command is not programmable.
You cannot use EDIT mode while a program is running.
The EDIT command allows two parameters. The first is a line identifier and the second is the increment between line numbers.
For example, the following command places the program on the CRT so that line 140 is in the current-line position, and new line numbers increment by 20.
EDIT 140,20
If the increment parameter is not specified, the computer assumes a value of 10. The following command places the program on the CRT so that line 1000 is in the current-line position, and new line numbers increment by 10.
EDIT 1000
When the line identifier is not supplied, the computer has different ways of assuming a line number.
The line identifier also can be a line label. A line label makes it very easy to find a specific program segment without needing to remember its line number. For example, if you want to edit a sorting routine that begins with a line labeled Go_sort, type:
EDIT Go_Sort
The line labeled Go_sort is placed in the middle of the display, with any lines that were immediately above and below this line.
To locate a program line in a subprogram context, you can use the FIND statement. See the subsequent section called "Global Editing Operations" for details.
When you go from normal mode to EDIT mode on a system with an ITF keyboard, the softkey menu and labels change to the User 2 menu (if the PDEV and KBD binaries are currently loaded).
While in EDIT mode on an ITF keyboard, you can switch softkey menus normally; use either the [Shift]-[Menu] key, or the appropriate statements (such as SYSTEM KEYS and USER 1 KEYS) to switch to other menus.
If you are in the User 2 menu when you exit EDIT mode, the system returns you to the menu that was in effect when you entered EDIT mode.
If you make errors while typing, use the [Back space] or [&left;] and [&right;] keys to move the cursor to the errors, then type them correctly. To insert characters, position the cursor to the right of where you want to insert, press [Insert Char], and type characters. Press [Insert Char] again to return to the typeover mode.
To enter a program line, type the desired characters at the keyboard. Once the line is exactly as you want it, you must press [Return] to store it. The cursor may be any place on the line when you store it; the system will read the entire line. For practice, type the lines shown below (the line numbers to the left are supplied for you).
10 PRINT "Tiny prog." [Return]
20 END [Return]
30
Program entry is simplified by the computer's ability to recognize the upper- and lower-case letter requirements for most elements in a statement. An entire statement can be typed using all upper-case or all lower-case letters. If the statement's syntax is correct, and there are no keyword conflicts, BASIC stores the program line. Upon LISTing or EDITing the program, however, BASIC uses these conventions:
You usually do not need to use [Shift] when entering a line, because BASIC automatically changes all letters to the proper letter-case. However, if there is a keyword conflict, an error is reported. A keyword conflict occurs when you try to use a keyword for an identifier (variable name, line label, or subprogram name). You can use keywords for identifiers; simply change the letter-case of at least one letter in the identifier name (for example, Cat or cAt), then press [Return] again. A word containing a mixture of upper- and lower-case letters is assumed to be an identifier. In general, if BASIC puts lower-case letters in something you thought was a keyword, then it wasn't really recognized as a keyword.
Before storing a program line, the computer checks for syntax errors, and also changes the letter-case of keywords and identifiers. Syntax describes the way keywords, parameters, etc. are put together to form a legal statement.
Immediate syntax checking is a major advantage of writing programs in the BASIC editor. Many programming errors can be detected while editing, which increases the chances of a program running properly, and cuts debugging time. If the line's syntax is correct, the line is stored, and the next line number appears in front of the cursor.
If BASIC detects an error in the input line, it displays an error message immediately below the line and places the cursor at the location it blames for the error.
10 PRINT "Short program.
-
Error 985 Invalid quoted string
20 END
You might not always agree with the editor's diagnosis of the exact error or the error's location. However, an error message definitely indicates that something needs to be fixed. You can find a complete list of error messages and their meanings in the "Errors" chapter of the HP BASIC 6.2 Language Reference.
To edit a line, it must be the current line--the line that the cursor is on. The following table gives a quick overview of standard editing keys (for the ITF keyboard) to use while editing the current line. The "Keyboard Information" chapter at the end of this manual lists all of the key definitions for each type of keyboard.
Editing\Feature | Explanation |
---|---|
Normal cursor (blinking underscore _) | When you type characters at the keyboard, they appear on the current line at the cursor, overwriting any existing characters. |
[(LEFT)], [(RIGHT)], and [Backspace] | Move the cursor one character in the indicated direction. If the cursor reaches either end of the line, it doesn't go any farther. Pressing [Shift]-[right arrow] moves the cursor to the end of the line, and [Shift]-[left arrow] moves the cursor to the beginning of the line. |
[Insert char] | Changes the cursor to the insert cursor (see below), and enters insert mode (characters typed appear before the current cursor position, and the cursor and subsequent characters shift one position to the right). This key toggles between the normal cursor and the insert cursor. |
Insert cursor (inverse-video block, {{ }}) | Indicates that the character entered is inserted in front of the character currently highlighted by the cursor. |
[Delete char] | Deletes the character pointed to by the cursor. Subsequent characters on the line shift one position to the left. |
[Clear line] | Deletes all characters from the cursor to the end of the current line. |
[Shift]-[Clear line] | Clears the entire current line. |
{{Set Tab}} ([f5]) and {{Clr Tab}} ([Shift]-[f5]) (System menu) | {{Set Tab}} and {{Clr Tab}} perform the indicated action at the cursor position. |
[Tab] and [Shift]-[Tab] | The [Tab] key moves the cursor to the next tab position, if there is one. [Shift]-[Tab] moves the cursor back to the previous tab position, if there is one. |
{{Any Char}} ([f7] System menu) | Characters that don't appear on the keycaps can be typed by using this
key. Assume you are typing a program line and you want the vertical bar
character, but it is not on your keyboard. Press the {{Any Char}} key. The
following message appears below the current line:
ENTER 3 DIGITS, 000 THRU 255 The decimal ASCII code for a vertical bar is 124. Press the [1][2][4] number keys. A vertical bar appears at the cursor position, and the message goes away. If you press a key that is not part of a 3-digit number in the proper range, the ANY CHAR operation is aborted and the key performs its normal function. |
Softkeys [f1] thru [f8] (in the User 1, 2, and 3 menus of ITF keyboards) | These keys produce characters and system-key presses, as if you had typed them at the keyboard. See the Using Softkeys section of the Introduction to the System chapter in this manual for details. |
All EDIT mode text-entry capabilities apply to the current line. You must move a line to the current-line position before you can edit it. The only exception to this is when you enter a new line with the same line number as an existing line. In that case, the new line replaces the old, even though the old line was not moved to the current-line position. The text on the screen is scrolled so that you are always editing the line in a window in the middle of the screen.
Editing Key | Explanation |
---|---|
[up arrow] | Scrolls the program up one line, so that you will be editing the next program line. |
[down arrow] | Scrolls the program down one line, so that you will be editing the preceding program line. |
[Shift]-[up arrow] | Jumps to the end of the program. |
[Shift]-[down arrow] | Jumps to the beginning of the program. |
Lines can be easily inserted into a program. As an example, assume that you want to insert some lines between line 90 and line 100 in your program. Place line 100 in the current-line position, and press the [Insert line] key.
90 PRINT "Line 90."
100 PRINT "Line 100." Make this the current line, then press [Insert line]
A new line number appears between line 90 and line 100.
90 PRINT "Line 90."
91 _ Begin typing; letters appear at the cursor
100 PRINT "Line 100."
Type and store the inserted lines in the normal manner. Appropriate line numbers appear automatically. The insert mode is canceled by pressing the [Insert line] key again, or by performing an operation that causes a new current line to appear (such as scrolling).
Lines can be deleted one at a time or in blocks. The [Delete line] key deletes the current line.
Before deletion:
90 PRINT "Line 90."
100 PRINT "Line 100." Make this the current line, then press [Delete line]
110 PRINT "Line 110."
After deletion:
90 PRINT "Line 90."
110 PRINT "Line 110." New "current line"
If you press [Delete line] by mistake, you can recover the line by pressing {{Recall}} ([f8]), then store it by pressing [Return]. BASIC has a recall buffer that holds the last lines entered, deleted, or executed. You can cycle through these lines, most recent to less recent, by repeatedly pressing {{Recall}}. [Shift]-[f8] cycles through from the current line to the more recent lines. You can clear this recall buffer by executing SCRATCH R to keep others from seeing passwords that you have typed.
When the keyword DEL is followed by a single line identifier, only a single line is deleted. The line identifier can be a line number or a line label. The [Delete line] key produces the same results, but has some advantages:
Therefore, DEL is more useful for deleting blocks of lines (described in the subsequent section called "Deleting Multiple Lines.")
Although the computer supplies a line number automatically, you can change that line number easily. Use [Back space] to place the cursor over the line number and type the line number you want to use. You can copy existing lines to another part of the program by changing their line number. However, there is an easier way to copy program lines--by using the COPYLINES command, described in "Copying Program Segments" later in this chapter.
Here are some points to keep in mind when changing the line numbers supplied by BASIC.
You can terminate the EDIT mode in several ways. Your choice depends upon what you want to do next. If you simply want to return the CRT to its normal state, press [Stop] (PAUSE) or [Clear display].
You can also leave EDIT mode by proceeding with another operation. The most useful choices in this case are LIST, CAT, [Reset] ([Shift]-[Break]), {{RUN}} ([f3]), or {{Step}} ([f1], system menu). EDIT mode is also terminated by a GET or LOAD, and by any operation that uses the display. Some examples follow:
LIST [Return]
STORE "MyProg" [Return]
RUN [Return]
or pressing {{RUN}}.
The preceding sections show how to edit single program lines. This section shows how to perform editing operations that may affect the entire program.
BASIC\Command | Purpose and Example Command | Softkey\(User 2 Menu) |
---|---|---|
REN | Renumbers the program (or a specified segment of the program). REN 100,10 | [f1] |
INDENT | Indents lines in a program to show the nesting of the branching constructs (such as FOR..NEXT and REPEAT..UNTIL). INDENT 7,2 | [f8] |
FIND | Searches the program for a specific textual pattern. FIND a pattern | [f6] |
CHANGE | Searches for a textual pattern, and gives you the option of changing it to a new pattern. CHANGE old text TO NEW CHARACTERS | [f7] |
COPYLINES | Copies (duplicate) program line(s) to another location in a program. COPYLINES 10,300 TO 550 | [f5] |
MOVELINES | Moves program line(s) to another location in a program. MOVELINES 450,522 TO 10 | [f4] |
DEL | Deletes program segments (ranges of program lines). DEL 100,150 | Not a default softkey. |
After an editing session with many deletes and inserts, you can improve the appearance of your program by renumbering. This also helps make room for long inserts. Renumber programs with the REN command.
This example renumbers the entire program in memory, starting at line number 10, and incrementing line numbers by 10 (the default values):
REN
Both the starting line number and the interval between lines can be specified. The following example renumbers the program, from line 100 to the end, incrementing by 5:
REN 100,5
If the increment value is not specified, 10 is assumed. The command below renumbers the program, from line 1000 incrementing by 10.
REN 1000
You can also renumber only a specified portion of a program. The following command renumbers lines in the range 1000 to 2000:
REN 1000,10 IN 1000,2000
INDENT is a non-programmable command. You can use it to scan an entire program, indenting it to nest program segments defined by the following cases:
For complete list of the statements that define these constructs see the HP BASIC 6.2 Language Reference description of the INDENT command.
The following program shows the indentation performed by this command:
INDENT 7,2
The first parameter (7) indicates the indentation of the outermost program segment; the second parameter (2) shows how many additional spaces each subsequently nested segment is indented. Notice how indentation improves readability.
10 FOR I=1 TO 5
20 REPEAT
30 INPUT "How old are you?",Age
40 Reasonable=1 ! Assume they're telling the truth...
50 IF Age<0 THEN
60 DISP "A negative age implies you are not born."
70 Reasonable=0
80 ELSE
90 IF Age>120 THEN
100 DISP "Are you sure?!"
110 Reasonable=0
120 ELSE
130 IF Age>100 THEN
140 DISP "You are pretty spry!"
150 ELSE
160 IF Age>80 THEN
170 DISP "Wow! Most people your age don't use computers much."
180 ELSE
190 DISP "Glad to meet you."
200 END IF
210 END IF
220 END IF
230 END IF
240 WAIT 4
250 UNTIL Reasonable
260 DISP "You were";Age*365.2422;" days old on your last birthday."
270 WAIT 3
280 NEXT I
290 END
When indentation parameters attempt to force program statements too far to the right, they are bounded by the width of the screen minus 8 characters. On an 80-column screen, a program line will never start to the right of column 72. Instead, all lines which should be indented farther to the right of this column will begin in this column. Line beginnings drop back to the left when the nesting level decreases to one increment less than 72.
To remove all indenting, execute this command:
INDENT 7,0
When programs are larger than a couple of screenfuls, it is handy to have the computer search for items such as variable names, numeric or string literals, and comments. Use the non-programmable FIND command to do this.
The following example searches the current program for the letters A pattern , beginning at the current line. . These letters may be a variable name, a string or numeric literal, a comment, or a portion of any of these.
FIND "A pattern" [Return]
If you want to begin the search in a different place, then specify the range of lines to be searched:
FIND "A pattern" IN 200,650 [Return]
When you execute this command, BASIC begins a search for these characters. The following message is shown in the message/results line below the keyboard input line:
Finding "A pattern"
If the pattern is not found, then the system displays the following message:
"A pattern" not found
If an occurrence of these letters is found, the system displays the program line containing the pattern and a confirmation:
300 PRINT "A pattern of circles is shown on the display."
Found "A pattern"
You can choose any of the following actions:
If you choose to remain in FIND mode, press [Return]. After checking the line's syntax, FIND searches for the next occurrence of the specified characters. If the modified line contains a syntax error, you may correct the error and press [Return] again. Once the line is syntactically correct, FIND searches for the next occurrence of the specified string.
You will remain in FIND mode as long as the FIND command has additional program lines to search. To remind you that you are in this mode BASIC displays these prompts at the bottom, right-hand corner of the screen.
Command
*
If you want to abort the FIND command, use the [Break] (Clr I/O) key to cancel the mode. BASIC will display:
Search aborted at nnnnn; "A pattern" not found.
in which nnnnn is the line number at which the FIND was aborted.
The CHANGE command is similar to FIND, except that you specify both a search pattern and a replacement pattern.
The following example searches for the pattern Old text and replaces it with New characters:
CHANGE "Old text" TO "New characters" [Return]
As with FIND, the system shows that it is busy searching for a pattern:
Finding "Old text"
CHANGE pauses when it finds the first occurrence of the search pattern; however, CHANGE also replaces the old pattern with the new one, and waits for you to confirm or reject the change:
200 PRINT "New characters."
"Old text" to "New characters"?
If you want only the occurrences of the pattern in a certain program segment to be changed, use the following syntax:
CHANGE "old" TO "New" IN 1, 250
If you want all occurrences of the pattern changed, with no capability of confirming/rejecting the changes, use the following syntax:
CHANGE "old" TO "New" ; ALL
You can also combine these two specifications to change all occurrences within a range of lines:
CHANGE "old" TO "New" IN 1, 250; ALL
COPYLINES provides an easy way to duplicate several lines of BASIC code in another location of the program. You must make sure the line number to which you copy does not already exist.
The following example copies lines 180 through 220 to a location beginning at line 5205:
COPYLINES 180,220 TO 5205 [Return]
The following example copies lines 300 through 3005 to a location beginning at line 100:
COPYLINES 300,3005 TO 100 [Return]
If the line you try to copy to already exists, an error occurs and no lines are copied. You cannot copy to an existing line number.
Use MOVELINES to move several program lines at a time. You must make sure the destination line number does not already exist.
The following command moves lines 32 through 127, inclusive, to a spot beginning at line 453:
MOVELINES 32,127 TO 453 [Return]
The following command moves lines 300 through 3005 to a location beginning at line 100:
MOVELINES 300,3005 TO 100 [Return]
If the line you designate as a destination already exists, an error occurs and no lines are moved. You cannot move lines to an existing line number.
You may frequently use MOVELINES to move program lines from a main program into a separate subprogram (defined by SUB and SUBEND). To do so you must go to a line below all of the existing lines in memory and enter the SUB statement.
2100 SUBEND
2110 SUB New_subprogram
2120 _
After you type this subprogram heading, you can use MOVELINES to move program lines from the main program (or from another subprogram) into the new subprogram:
MOVELINES 350,499 TO 2120
Don't forget to delimit the end of the new context with a SUBEND statement!
2630 SUBEND
2640 _
DEL can be used to delete several lines in a single operation. Delete blocks of program lines by using two line identifiers in the DEL command.
The line identifiers must appear in the same order they do in the program. Here are some examples.
The following command deletes lines 100 through 200, inclusively:
DEL 100,200
This command deletes all the lines from the one labeled Block2 to the end of the program:
DEL Block2,32766
This command would do nothing except generate an error:
DEL 250,10
Subprograms or user-defined functions in your program can only be deleted in certain ways (such as with DELSUB). Primarily, the SUB or DEF FN statement cannot be deleted without deleting the entire subprogram or function. This subject is explained fully in the "Subprograms" chapter of the &progd;.
DEL is not programmable and cannot be used while a program is running.
Good program documentation can make the difference between a supportable tool that adapts to the needs of the users and a support nightmare that never really does exactly what the current user wants. Keep in mind that the local software support person just might be you.
BASIC makes it easy to write self-documenting programs. In addition to BASIC's standard REM (remark) statement, additional documentation features are:
All of these features work together to make a readable program. The following example shows two versions of the same program. The first version is uncommented and uses traditional BASIC variable names. The second version uses the features of HP's BASIC language to make the program more easily understood. Which version would you rather support?
100 PRINTER IS 1
110 A=.03
120 B=.02
130 X=0
140 Y=0
150 C=A=B
160 PRINT " Item Total Total"
170 PRINT " Price Tax Cost"
180 PRINT "------------------------------"
190 P=0
200 INPUT "Input item price",P
210 D=P*C
220 E=P=D
230 X=X=D
240 Y=Y=E
250 DISP "Tax =";D;"Item cost =";E
260 PRINT P,X,Y
270 GOTO 190
280 END
100 ! This program computes the sales tax for
110 ! a list of prices. Item prices are input
120 ! individually. The tax and total cost for
130 ! each item are displayed. The running
140 ! totals for tax and cost are printed on
150 ! the CRT. Modify line 220 to change the
160 ! the system printer.
170 !
180 ! Sales tax rates are assigned on lines 230
190 ! and 240. The rates used in this version
200 ! of the program were in effect 1/1/81.
210 !
220 PRINTER IS CRT ! Use CRT for printout
230 State_tax=.03 ! Local tax rates
240 City_tax=.02
250 !
260 Total_tax=0 ! Initialize variables
270 Total_cost=0
280 Tax_rate=State_tax=City_tax
290 ! Print column headers
300 PRINT " Item Total Total"
310 PRINT " Price Tax Cost"
320 PRINT "------------------------------"
330 !
340 LOOP ! Start of main "Get Price" loop.
350 Price=0 ! Don't change totals if no entry.
360 INPUT "Input item price",Price
370 Tax=Price*Tax_rate
380 Item_cost=Price=Tax
390 Total_tax=Total_tax=Tax ! Accumulate totals.
400 Total_cost=Total_cost=Item_cost
410 DISP "Tax =";Tax;" Item cost =";Item_cost
420 PRINT Price,Total_tax,Total_cost
430 END LOOP ! Repeat loop for next item.
440 END
You can list the program on the current PRINTER IS device (usually the CRT) by executing the following command. (The EDIT binary must be loaded in order to use LIST and EDIT.)
LIST [Return]
(If the keyword LIST is executed without parameters, the assumed action is to list the entire program on the system printer.)
The LIST statement allows parameters that specify both the range of lines to be listed and the device to which the listing is sent.
Starting and ending line numbers can be specified in the LIST statement. For example, the following command lists lines 100 through 200, inclusively.
LIST 100,200
The following example lists the last portion of the program, from line 1850 to the end.
LIST 1850
Line identifiers can also be labels. The following command lists the program from the line labeled Rocket to the end.
LIST Rocket
The default system printer after a power-on or SCRATCH A is the CRT.
If you want a listing on a printer, you have two choices.
PRINTER IS 701
LIST
The parameter 701 identifies the printer connected to the computer through the interface at select code 7 (the built-in HP-IB); the printer itself has an address setting of 01. You can also use the PRT function, which returns a value of 701.
However, it is often desirable to keep the CRT display as the system printer and still get program listings on an external printer.
LIST #701
When both the printer and the line range are specified, the printer number is specified first and terminated with a semicolon. This command lists lines 200 through 500 on the device connected to the interface at select code 12:
LIST #12; 200,500
To write a program to a mass storage device, use either SAVE or STORE. There is no right or wrong choice; your choice depends upon the kind of file you want.
The main advantage of an ASCII file is that it can be read as data by a BASIC program or by LIF-compatible devices (such as other HP computers and terminals). LIF is the acronym for Logical Interchange Format, a disk format used by several HP divisions. (The first letter of the file name must be a letter; in addition, some LIF-compatible devices restrict file names to upper-case letters and the decimal digits 0 through 9.)
Characteristic | SAVE | STORE |
---|---|---|
File type created: | ASCII | PROG |
Retrieved by: | GET | LOAD |
Approximate storage speed: | 900 bytes/s | 13 000 bytes/s1 |
Approximate retrieval speed: | 300 bytes/s2 | 14 000 bytes/s1 |
Can file be read as data? | Yes | No |
LIF-compatible file? | Yes | No |
Arbitrary program segments allowed? | Yes | No |
Subprograms included? | Yes | Yes |
Can use LOADSUB to retrieve a subprogram? | No | Yes |
Stores CSUBs correctly? | No | Yes |
1The speeds for LOAD and STORE are approximate for an interleave factor of 1 on an HP 9836 internal disk drive. Interleave factors greater than this cause a corresponding decrease in speed.
2The retrieval speed for GET is very data-dependent. On an HP 9836 with a clock rate of 8 MHz, it can vary from 20 bytes/second to 600 bytes/second (and maybe beyond those limits) according to the contents of the file and the syntax checking required to enter the lines into program memory. See the "Efficient Use of the Computer's Resources" in the HP BASIC 6.2 Advanced Programming Techniques for a discussion of how to time various computer operations.
The following command creates a program file called MyProgFile on the current default volume:
STORE "MyProgFile"
If you get error 54, it means a file with the name you are using is already on the disk. You have three choices:
RE-STORE "BEAMS" RE-STORE must include the hyphen
NOTE |
---|
Use STORE to store to a new file name that doesn't exist. Use RE-STORE if the name already exists. Use the LOAD statement to load a file that has been STOREd. |
SAVE is similar to STORE in that it stores the current program in a file; however, it has additional features. SAVE creates an ASCII file and allows line identifiers that specify what portion of the program you want to save. This is especially helpful when you move or append program segments during major editing operations. Here are some examples.
SAVE "WHALES" Saves the entire editor contents
SAVE "LastPart",500 Saves from line 500 to end
SAVE "Sorter",Sort,Printout Saves lines from label Sort to label Printout
RE-SAVE "Analysis" Replaces old Analysis program with new version
NOTE |
---|
Use SAVE to save to a new file name that doesn't exist. Use RE-SAVE if the name already exists. Use the GET statement to retrieve a file that has been SAVEd. |
There may be times when you want to keep portions of your programs from being read or used by others. With BASIC, you can prevent others from reading or executing a program unless you give the authorization. SECURE prevents program line(s) from being listed.
CAUTION |
---|
Once a program is secured, it cannot be unsecured. Do not secure the only copy of your program. Keep an unsecured "source code" copy of the program in a safe location. |
The following example secures lines 30 through 60 from being listed (either with the editor or by using the LIST statement):
SECURE 30,60
Here is what the program might look like--either with the editor or as the output of a LIST statement:
10 ! Example of SECURE'd program.
20 ! Begin password check routine.
30*
40*
50*
60*
70 ! End of password check.
80 .
.
.
If you want the whole program to be secured, use this statement:
SECURE
BASIC also provides a method to prevent unauthorized execution of programs. You can write a routine that includes the following statement; it checks the serial number of a computer, or the serial number of an optional HP 46084 ID Module. Then your routine can determine whether or not to permit the rest of the program to execute.
SYSTEM$("SERIAL NUMBER") Reads the computer's
ID PROM or returns encoded contents
To decode an ID Module's contents, use the "ID_MODULE" program supplied on the Manual Examples disk.