Source Program Divisions

From CometWiki

Revision as of 08:08, 31 May 2009 by Badge (Talk | contribs)
Jump to: navigation, search

Source Program Divisions

Internet Basic source programs are arranged into three functional divisions.

Data Division The Data Division defines the data variables to be used in the program.

I/O Format Division The I/O Format Division establishes the exact formats and device control codes for all input/output aspects of the program.

Procedure Division The Procedure Division, contains the executable statements of the program, including data initialization and assignment, input and output statements, program flow control, decision making and looping, and exception handling.

So, a typical Internet Basic source program looks like this:

Data Division
.
.
I/O Format Division
.
.
Procedure Division
.
.

Note: Even though the Data Division and I/O Format Division are shown as separate sections of a source program, they may be combined and intermixed. That is, format statements may be used in the Data Division and vice versa. The only requirement is that data elements used in format statements must be defined prior to their use. Other than that, it is sometimes more convenient to think of the Data Division and I/O Format Division as one section of the source program, rather than two.

Here's a sample program (note that this program does not contain any instructions in the I/O Format Division).

! Data Division
	LENGTH 6.2 & LOCAL Fahrenheit,Celsius

LENGTH 1 & LOCAL Choice$,Answer$

 !
! I/O Format Division
!
!
! Procedure Division
!
 Top:	Print (CS)
!

Print "This program converts between temperature scales." , @(0,3)

!

Print "Enter 1 to convert from Fahrenheit to Celsius, or" , @(0,5) Print "enter 2 to convert from Celsius to Fahrenheit." , @(0,6)

!
Choice:

Print "Your choice?" , @(0,8) Input @(14,8),Choice$

 !

SELECT CASE Choice$

 !

CASE "" STOP

 !

CASE "1" Print "Enter Fahrenheit temperature:" , @(0,10) Input @(30,10),Fahrenheit Celsius = (Fahrenheit - 32) / 1.8 Print "Celsius temperature is:",@(0,12) ; Celsius,@(30,12)

 !

CASE "2" Print "Enter Celsius temperature:" , @(0,10) Input @(30,10),Celsius Fahrenheit = Celsius*1.8 + 32 Print "Fahrenheit temperature is:",@(0,12) ; Fahrenheit,@(30,12)

 !

CASE ELSE Print "Please enter 1 or 2." , @(0,10) GOTO Choice

  !

ENDSELECT

 !

Print "Would you like to perform another conversion? (Y/N)" , @(0,14) Input @(52,14),Answer$

  !

Answer$ = UCASE(Answer$)

  !
	IF Answer$ = "Y" THEN

GOTO Top ELSE STOP ENDIF

  !
    END
Personal tools