• Aucun résultat trouvé

Global Program Editing

Dans le document Programming Guide, (Page 31-37)

The Getting Started Guide for your particular Technical BASIC system describes entering pro-grams using the BASIC editor; it also describes editing propro-grams on a line-by-line basis. This section describes the following "global" program editing operations which are provided by Tech-nical BASIC keywords:

• Inserting new program lines between existing lines.

• Deleting existing lines.

• Renumbering existing lines.

• Scanning for string literals.

• Renaming variables.

• Copying and moving program segments.

/

~

(

Inserting Lines

Lines can be easily inserted into a program. As an example, assume that you want to insert some lines between line 200 and line 210 of our example program.

180 LET TargetIncome(1)=1680.00 190 LET TargetIncome(2)=345.67 200 !

210 DISP" Category Target"

220 DISP "--- ---"

You can begin by numbering the first line 201, the second one 202, and so forth (up through 209 without overwriting existing lines).

201 CLEAR! Clear the alpha screen.

202

Note that while inserting lines, you should keep track of the line numbers you have inserted so that you do not inadvertantly:

• Overwrite existing lines .

• Insert lines into the wrong place.

You can generate a program listing with LIST or PLIST to keep track of where lines have been placed.

180 190 200 201 202 210 220

LET TargetIncome(1)=1680.00 LET Targetlncome(2)=345.67

!

CLEAR ! Clear the alpha screen.

DISP " Category DISP

"---Target"

---"

Deleting Lines

The DELETE command can be used to delete single or groups of program lines. When the keyword DELETE is followed by a single line number, only a single line is deleted. For example, executing:

DELETE 201

deletes only line 201 of your program.

Blocks of program lines can be deleted by using two line numbers in the DELETE command. The first number identifies the start of the segment to be deleted, and the second number identifies the end of the segment to be deleted. Here are some examples.

DELETE 100,200 DELETE 150,65535 DELETE 100, 10

deletes lines 100 thru 200, inclusively.

deletes all the lines from line 150 through the end of the program.

would do nothing except generate an error if a program is currently in memory.

Renumbering a Program

No matter how careful you have been while entering lines, there will inevitably be a time when you need to renumber a program. And it is also good practice to renumber occasionally to improve readability.

You can renumber a program by using the REN command. When no parameters are specified, the first line number is renumbered to 10 and the line-number increment is 10.

Both the starting line number and the interval between lines can be specified. For example, this command renumbers the entire program, using 100 for the first line number and an increment of 5.

You can also renumber a portion of a program. For instance, this command renumbers only line numbers 1000 through 1080 to lines 10 through 90.

REN 10,10,1000,1080

10 ! Allocate memory for data storage.

20 OPTION BASE 1 30 DIM IncomeName$(2) 40 REAL TargetIncome(2) 50 !

60 ! Assign values to variables.

70 LET IncomeName$(l)=IIPayroll"

80 LET IncomeName$(2)=IIInvestments"

90 LET TargetIncome(1)=1680.00 1090 LET TargetIncome(2)=345.67 1100 !

1110 CLEAR! Clear alpha display.

1120 !

1130 DISP II Category Target II

1140 DISP ,,--- ---"

1150 DISP IncomeName$(l),Targetlncome(l) 1160 DISP IncomeName$(2),TargetIncome(2)

NOTE

Note that the REN command cannot be used to move lines. Moving and copying program lines is the topic of a subsequent section.

To get back to the original program, you can use this sequence:

DELETE 1110,1120 REN 100

Scanning for Literals

The SCAN command is used for finding all the occurrences of a particular string literal or variable name in a program. In our continuing example program, let's look for the literal "Income":

SCAN "Income"

(

Here is the system's response:

Scanning ...

130 REAL Targetlncome(2)

180 LET Targetlncome(1)=1680.00 190 LET Targetlncome(2)=345.67

210 DISP" Category Target"

230 DISP IncomeName$(l),Targetlncome(l) 240 DISP IncomeName$(2),Targetlncome(2)

... end of scan

Here is a more useful example. Suppose that you have the string literal "Tax" in several places in your program, and you want to change it to either "State Tax" or "Federal Tax" - and which one you change it to depends on the context of the statement. Use the following command to find and list all occurrences of the string "Tax":

SCAN "Tax"

You can then look at each line and decide whether it should be changed to "State Tax" or

"Federal Tax".

To verify that all change(s) have been made, execute another SCAN command specifying the string for which you were originally searching. (Using this command avoids a long listing of the program.) The command lists all program lines containing the string "State Tax" or "Federal Tax", since the string "Tax" is a subset of those strings.

Renaming Variables

You can rename variables with the the REPLACEVAR ... BY command. Here is an example:

REPLACEVAR Targetlncome BY TargetExpense

REPLACEVAR ... BY is like SCAN in that it looks for specific patterns of characters; however, RE-PLACEVAR is different in two ways:

• It can only find occurrences of the specified variable name, not any combination of char-acters in the program .

• It automatically replaces the first variable name with the second one.

Here is an example of replacing one variable name with another. Suppose that you have the following program in memory:

You decide after entering the program that you want to replace the variable "T" with the variable name "RESULT" , but you do not want to go through the program and replace "T"

with "RESULT" everywhere you see it as it would take a long time to do so. This is particularly true for large programs. The following command allows you to do this:

REPLACEVAR T BY RESULT

When you do a listing of you program it now looks like this:

10 A=20 20 B=30 30 RESULT=A+B 40 DrSp RESULT 50 RESULT=A*B 60 Drsp RESULT 70 END

Dans le document Programming Guide, (Page 31-37)

Documents relatifs