Bringing in programs from separate files, Bringing in programs from separate files -9 – Rockwell Automation 1747-PBASE BASIC Development Software Programming Manual User Manual

Page 81

Advertising
background image

Publication 1746-PM001A-US-P

Writing Programs Using the BASIC Development Language 6-9

Example:

A programming macro is written to set the wall clock’s day, month, and year. The
macro is named Setdate and is defined by the BASIC lines between

{$MACRO...}

and

{$ENDM}

. After the programming macro is defined, it can be called again any

number of times, anywhere in that program, by simply programming the name
Setdate.

Example:
Before translation:

After translation:

REM CREATE PROGRAM MACRO

0 REM ...

{$MACRO Setdate(%1, %2, %3)}

1O REM CREATE PROGRAM MACRO

PUSH %1

20 D=16

PUSH %2

30 M=06

PUSH %3

40 Y=90

CALL 41

50 PUSH D

{$ENDM}

60 PUSH M

D=16

70 PUSH Y

M=06

80 CALL 41

Y=90

Setdate(D,M,Y)

If you have a large number of your own programming macros or a number of them
that you use frequently, you may wish to create a file containing only those macros.
You could then include that file in all of your programs. For example, if you made
a programming macro file named

mine.bdl

, you could then begin all of your

programs with the command

{$I Mine.bdl}.

This would include that file

during translation and allow you to use your programming macros throughout the
program.

Bringing in Programs
from Separate Files

Depending on the circumstances, you may want to access other programs from
your program, or you may wish to copy other programs directly into your program.
There are several methods for accomplishing this.

When choosing between accessing a program as a subprogram or inserting it into
your main program, consider the following:

the size of the program you wish to access or insert

the frequency with which you need to execute it from your main program

whether it is or may be used as a subprogram for other programs

whether inserting it makes your main program unmanageably large

IMPORTANT

If you are unable to merge or edit files, those files have probably
been locked. Files can be locked (made read-only) or unlocked
through the

Information about current file

option from

the File menu.

Advertising