A Sample Program

As an example, you can create a simple program called ADDNUMS; it returns the sum of two numbers.

Before you write the program, you need a program file. The source code for an mvBASIC program is entered as an item in the program file. By convention, the program file for an account is called BP (for Basic Programs). The program file is created with the CREATE-BFILE command.

>CREATE-BFILE BP 1 3

[417] FILE 'BP' CREATED; BASE = 10999, MODULO = 1.

[417] FILE 'BP' CREATED; BASE = 11000, MODULO = 3.

>

The command in the preceding example creates a program file, with a modulo of 1 for the file dictionary and a modulo of 3 for the data file. The new source code can now be placed in item ADDNUMS in the program file BP. For writing the program, use the Editor:

>ED BP ADDNUMS

NEW ITEM

TOP

.I

001+PRINT "ENTER ONE NUMBER":

002+INPUT NUM1

003+PRINT "ENTER ANOTHER NUMBER":

004+INPUT NUM2

005+2INT_SUM = NUM1 + NUM2

006+PRINT "THE SUM OF ":NUM1 : " AND ":NUM2:" IS ":2INT_SUM

007+STOP

008+END

009+ <RETURN>

TOP

.FI

'ADDNUMS' FILED.

 

>

Compile the program with the COMPILE command, translating the program’s source code into object code.

>COMPILE BP ADDNUMS

********

SUCCESSFUL COMPILE!   1 FRAMES USED.

 

>

The program compiles without error. Once the program is compiled, execute it with the RUN command.

>RUN BP ADDNUMS

ENTER ONE NUMBER?4

ENTER ANOTHER NUMBER?9

THE SUM OF 4 AND 9 IS 13

 

>

The program runs successfully on the first attempt. You can now catalog it, so that you can use it as if it were a command:

>CATALOG BP ADDNUMS

[244] 'ADDNUMS' CATALOGED!

 

>ADDNUMS

ENTER ONE NUMBER?5

ENTER ANOTHER NUMBER?3

THE SUM OF 5 AND 3 IS 8

 

>

You have created an mvBASIC program. More complex programs seldom compile the first time, and once they compile they don’t always run without error. However, the process remains unchanged: edit, compile, and run the program until it runs successfully.

See Also

Creating mvBASIC Programs

Creating the Program File

Editing and Listing the Source Code

Compiling the Program

Running the Program

Cataloging the Program