Chapter 2: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
m (replace does not work for every type of FILE, but it does work for a BR PROGRAM)
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
===2.1 Essential Commands ===
===2.1 Essential Commands ===
The information and exercises in this chapter will introduce you to the ground rules about managing Business Rules! programs. When you finish you will be able to :  
The information and exercises in this chapter will introduce you to the ground rules about managing Business Rules! programs. When you finish you will be able to :
 
 
- Explain the difference between commands and statements.  
*Explain the difference between commands and statements.  
- Write commands and a short program using PRINT statements.  
*Write commands and a short program using PRINT statements.  
- Use commands to CLEAR, RUN, LIST, SAVE, LOAD, and REPLACE Programs.  
*Use commands to CLEAR, RUN, LIST, SAVE, LOAD, and REPLACE Programs.  
- Print a directory listing using the DIR command
*Print a directory listing using the DIR command
- Recognize and respond to an error message.  
*Recognize and respond to an error message.  
- Edit program lines.  
*Edit program lines.  
 
 
Instead of starting you off with lots of boring stuff about programming theory, we're going to cheat a little and skip ahead to the fun part, writing commands and program statements with Business Rules!. First we will teach you the abilities of the PRINT command.  
Instead of starting you off with lots of boring stuff about programming theory, we're going to cheat a little and skip ahead to the fun part, writing commands and program statements with Business Rules!. First we will teach you the abilities of the PRINT command.
 


===Commands VS Statements ===
===Commands VS Statements ===
Line 35: Line 34:


====Quick Quiz 2.1 ====
====Quick Quiz 2.1 ====
 
1) Match the following:
1) Match the following:


Line 46: Line 44:
|}
|}


2) When PRINT is followed by a mathematical operation, it performs like:  
2) When PRINT is followed by a mathematical operation, such as PRINT 8 * 4, it performs like:  


a)   A calculator.  
a)   A calculator. <br>
b)   The square root sign.  
b)   The square root sign. <br>
c)   A typewriter.  
c)   A typewriter. <br>


3) How would Business Rules! compute the following mathematical problems? Figure them out first by hand, then use PRINT to check your answers:
3) How would Business Rules! compute the following mathematical problems? Figure them out first by hand, then use PRINT to check your answers:
   
   
a)  2+8*6  
a)  2+8*6 <br>
b)  (3+4)/2  
b)  (3+4)/2 <br>
c)  5*5+82-63/3+13  
c)  5*5+82-63/3+13<br>
 
Answers:


1) a-1, b-2
[[Answers 2.1]]
2) a
3) a-50, b-3.5, c-99
 
 


===2.2 Using PRINT with delimiters===  
===2.2 Using PRINT with delimiters===  
 
 
You have used the PRINT command to print the results of a mathematical operation, but PRINT can also be used to print words, phrases, numbers and numeric formulas. When you want Business Rules! to print something exactly as you have written it, you must enclose it in single or double quotation marks. Try typing in the following command:  
You have used the PRINT command to print the results of a mathematical operation, but PRINT can also be used to print words, phrases, numbers and numeric formulas. When you want Business Rules! to print something exactly as you have written it, you must enclose it in single or double quotation marks. Try typing in the following command:  


Line 82: Line 76:
Business Rules! will print letters, spaces, and almost any symbol that is on your keyboard when you enclose them in either double ( " " ) or single ( ' ' ) quotation marks.  
Business Rules! will print letters, spaces, and almost any symbol that is on your keyboard when you enclose them in either double ( " " ) or single ( ' ' ) quotation marks.  
   
   
====Quick Quiz 2.2 ====
====Quick Quiz 2.2====
1) When used with PRINT, delimiters are:  
1) When used with PRINT, delimiters are: <br>
a)  Lines that mark the beginning and end of a program.  
a)  Lines that mark the beginning and end of a program. <br>
b)  Symbols that mark the beginning and end of information to be printed.  
b)  Symbols that mark the beginning and end of information to be printed. <br>
c)  Symbols that tell Business Rules! to ignore the current command.  
c)  Symbols that tell Business Rules! to ignore the current command. <br>


2) True or False - PRINT prints quotation marks when you use them as delimiters.
2) True or False - PRINT prints quotation marks when you use them as delimiters, for example, PRINT "Greetings, Earthlings"


3) Which of the following pairs of symbols can be used as delimiters with PRINT?  
3) Which of the following pairs of symbols can be used as delimiters with PRINT? <br>
a)  & &  
a)  & & <br>
b)  * #  
b)  * # <br>
c)  " "  
c)  " " <br>
d)  " '  
d)  " ' <br>
e)  ' '  
e)  ' ' <br>


Answers
[[Answers 2.2]]
1 - b, 2 - false, 3 - c, e


===2.3 Getting your first ERROR ===
===2.3 Getting your first ERROR ===
 
You might know that falling properly is one of the first things you learn when you take martial arts. Well, learning to fall is important when it comes to programming too, but in this case it's called getting an error.  
You might know that falling properly is one of the first things you learn when you take martial arts. Well, learning to fall is important when it comes to programming too, but in this case it's called getting an error.  
 
 
Sending error messages is Business Rules! way of telling you that it doesn't understand your instructions. Since Business Rules! has a much smaller vocabulary than you do and since Business Rules! requires you to present command or statement information in a very specific order you may frequently find yourself getting error messages.  
Sending error messages is Business Rules! way of telling you that it doesn't understand your instructions. Since Business Rules! has a much smaller vocabulary than you do and since Business Rules! requires you to present command or statement information in a very specific order you may frequently find yourself getting error messages.  
 
 
It is important to remember that nothing you type into Business Rules! will harm your computer. Unless you physically attack your hardware, chances are extremely small that it will blow up, melt or otherwise self-detonate. Don't worry!
Don't worry! Error messages are a frequent occurrence even for the most experienced programmers. For you, the student, error messages can become a valuable part of the learning experience which tell you about what BR expects you to do.
 
 
To get your first error, try typing in the following:  
To get your first error, try typing in the following:  
 
 
PRINT "Hi
PRINT "Hi
 
 
Notice the end quote is missing, and this results in an error. Now press ENTER. Your computer should respond with an obnoxious beep. If you look in the status line on the bottom row of the screen you will see the word ERROR in the left corner and the number 1003 in the center.  
Notice the end quote is missing, and this results in an error. Now press ENTER. Your computer should respond with an obnoxious beep. If you look in the status line on the bottom row of the screen you will see the word ERROR in the left corner and the number 1003 in the center.  


[[image:2.1.png]]
[[image:2.1.png]]


The number is the error code and identifies the type of error which occurred. If an error does occur then you can search the wiki by error number in order to find its meaning and possible solutions. (Always search for error numbers using four digits, i.e. if it’s error 745, search for 0745).
The number is the error code and identifies the type of error which occurred. Typing in BRERR$(1003) will show you the error message. If an error does occur, then you can search the wiki by error number in order to find its meaning and possible solutions. (Always search for error numbers using four digits, i.e. if it’s error 745, search for 0745).


"End quote not found" is the description for error [[1003]]. Looking back at the command, you can see that this error happened because you didn't include the ending quotation mark or delimiter that tells Business Rules! to print the information between it and the beginning delimiter exactly as it appears.  
"Missing quote" is the description for error [[1003]]. Looking back at the command, you can see that this error happened because you didn't include the ending quotation mark or delimiter that tells Business Rules! to print the information between it and the beginning delimiter exactly as it appears.  


You can correct the command by using your arrow keys to move the cursor to the end of the line, and then adding the quotation mark right after the exclamation point. The correct command should look like this:  
You can correct the command by using your arrow keys to move the cursor to the end of the line, and then adding the quotation mark right after the exclamation point. The correct command should look like this:  
 
 
PRINT "Hi!"  
PRINT "Hi!"  
 
 
====Quick Quiz 2.3 ====
====Quick Quiz 2.3 ====
 
 
1) You will receive ERROR messages when:  
1) You will receive ERROR messages when:  
a)  You tilt your computer.  
 
b)  Business Rules! doesn't understand your instructions.  
a)  You tilt your computer. <br>
c)  Business Rules! just doesn’t like you.  
b)  Business Rules! doesn't understand your instructions. <br>
c)  Business Rules! just doesn’t like you. <br>


2) An error code is:  
2) An error code is:  
a)  The word ERROR in your status line.  
 
b)  A series of beeps which identify the type of error which occurred.  
a)  The word ERROR in your status line. <br>
c)  A number which identifies the type of error which occurred.  
b)  A series of beeps which identify the type of error which occurred. <br>
 
c)  A number which identifies the type of error which occurred. <br>
 
3) Where can you find a listing of the different Business Rules! error codes and their meanings?  
3) Where can you find a listing of the different Business Rules! error codes and their meanings?  
a)  At the end of this chapter.  
 
b)  In the Error Handling chapter.  
a)  At the end of this chapter. <br>
c)  On the Internet at www.brwiki.ads.net, by typing the error code into the search engine.  
b)  In the Error Handling chapter. <br>
 
c)  On the Internet at brwiki.brulescorp.com, by typing the error code into the search engine. <br>
Answers:
 
1-b, 2-c, 3-c.
[[Answers 2.3]]
 


===2.4 Writing a program===  
===2.4 Writing a program===  
 
 
In previous sections you saw how PRINT can be used as a command to immediately print words, numbers or mathematical results. As you will see in this lesson, PRINT operates the same way when used as a statement in a program.  
In previous sections you saw how PRINT can be used as a command to immediately print words, numbers or mathematical results. As you will see in this lesson, PRINT operates the same way when used as a statement in a program.  


With Business Rules! loaded and READY, type in the following (always press ENTER after each line):
With Business Rules! loaded and READY, type in the following (always press ENTER after each line):


CLEAR
CLEAR


This command clears any programs or stray program lines which may be in the computer’s temporary memory.  You should get into the practice of using this command every time you begin writing a new program. If you wish to also clean off the screen, type in
This command clears any programs or stray program lines which may be in the computer’s temporary memory.  You should get into the practice of using this command every time you begin writing a new program. If you wish to also clean off the screen, type in


NEWPAGE
NEWPAGE


Now type the following lines exactly as they appear:       


Now type the following lines exactly as they appear:       
 
[[image:2.2.png]]
[[image:2.2.png]]
 
If you get an error, or if you make a typing mistake, you can use the arrow keys to reposition the cursor and type the information correctly. Remember to always press ENTER after each line. If you notice a typing mistake after you've already finished typing a line and pressed ENTER, just retype the entire line (don't forget the line number).
If you get an error, or if you make a typing mistake, you can use the arrow keys to reposition the cursor and type the information correctly. Remember to always press ENTER after each line. If you notice a typing mistake after you've already finished typing a line and pressed ENTER, just retype the entire line (don't forget the line number).
 
 
Business Rules! will automatically replace the old one with the new one and put it in the right order for you.  
Business Rules! will automatically replace the old one with the new one and put it in the right order for you.  
 
 
The STOP (STO) statement in line 60 simply tells the system to stop executing the program at this line. Since you are already familiar with PRINT, you can probably guess what lines 10-50 will do when this program is executed--but let's try it anyway. RUN is the command that you use to execute a program. Type RUN or (RU), then press ENTER.  
The STOP (STO) statement in line 60 simply tells the system to stop executing the program at this line. Since you are already familiar with PRINT, you can probably guess what lines 10-50 will do when this program is executed--but let's try it anyway. RUN is the command that you use to execute a program. Type RUN or (RU), then press ENTER.  
 
 
The computer should respond, and the lower portion of your screen should now say:  
The computer should respond, and the lower portion of your screen should now say:  
 
 
[[image:2.3.png]]
[[image:2.3.png]]
  
 
You can type RUN and press ENTER to re-execute your current program.  
You can type RUN and press ENTER to re-execute your current program.  


To see your program lines again, you can type LIST. The computer should respond with:  
To see your program lines again, you can type LIST. The computer should respond with:  
 
 
[[image:2.4.png]]
[[image:2.4.png]]
 
Hey! Business Rules! changed your program!  
Hey! Business Rules! changed your program!  
 
 
Your line numbers are now five digits long instead of two, and your statement keywords are now in uppercase instead of lowercase. Business Rules! automatically makes these changes to every program line that you enter. As you go through the rest of this tutorial, you will learn about keyword abbreviations and other typing shortcuts that you can use, but Business Rules! will always LIST your programs in its own preferred format.  
Your line numbers are now five digits long instead of two, and your statement keywords are now in uppercase instead of lowercase. Business Rules! automatically makes these changes to every program line that you enter. As you go through the rest of this tutorial, you will learn about keyword abbreviations and other typing shortcuts that you can use, but Business Rules! will always LIST your programs in its own preferred format.  
 
 
This has been a long lesson and you may be thinking that it's time for a break. If you exit Business Rules! now, you will lose the program you just wrote along with all the time and effort you put into typing it. To avoid such a grim occurrence, first SAVE the program to a file. To do this, type:  
This has been a long lesson and you may be thinking that it's time for a break. If you exit Business Rules! now, you will lose the program you just wrote along with all the time and effort you put into typing it. To avoid such a grim occurrence, first SAVE the program to a file. To do this, type:  
 
 
SAVE GRANDMA  
SAVE GRANDMA  
 
 
The name that you gave it, GRANDMA, is the same name you will use when you wish to recall the program from memory with the LOAD command (which you'll learn about in the next chapter).  
The name that you gave it, GRANDMA, is the same name you will use when you wish to recall the program from memory with the LOAD command (which you'll learn about in the next chapter).  
 
 
You can now type SY or SYSTEM to exit Business Rules!, or you can type NEWPAGE, and go on to the next lesson.  
You can now type SY or SYSTEM to exit Business Rules!, or you can type NEWPAGE, and go on to the next lesson.  
 
 
====Quick Quiz 2.4 ====
====Quick Quiz 2.4 ====
1) Match the following:
1) Match the following:
Line 196: Line 188:
|a. STOP (STO)||1. Stores a program on disk.  
|a. STOP (STO)||1. Stores a program on disk.  
|-
|-
|b. RUN (RU)||2. Last line of a program.  
|b. RUN (RU)||2. Terminate program execution.  
|-
|-
|c. LIST (LIS)||3. Exits Business Rules!.  
|c. LIST (LIS)||3. Exits Business Rules!.  
Line 207: Line 199:
2) What are two changes that Business Rules! makes to your program lines before it LISTs them?  
2) What are two changes that Business Rules! makes to your program lines before it LISTs them?  


a)  Fixes all spelling errors.  
a)  Fixes all spelling errors. <br>
b)  Changes lowercase letters to uppercase.  
b)  Changes lowercase letters to uppercase. <br>
c)  Increments every line number by ten.  
c)  Increments every line number by ten. <br>
d)  Lengthens all line numbers to five digits.  
d)  Lengthens all line numbers to five digits. <br>
e)  Makes every line the same length.  
e)  Makes every line the same length. <br>


3) What should you always do before exiting Business Rules!?  
3) What should you always do before exiting Business Rules!? <br>
a)  Log out.  
a)  Log out. <br>
b)  Save any programs or data you wish to keep.  
b)  Save any programs or data you wish to keep. <br>
c)  Use the CLEAR command to remove all information from temporary memory.  
c)  Use the CLEAR command to remove all information from temporary memory.  


Answers:
[[Answers 2.4]]
1-a-2., b-5., c-4., d-1., e-3.;
2-b and d;
3-b


===2.5 DIR & LOAD command ===
===2.5 DIR & LOAD command ===
Line 229: Line 218:
   
   
Type in DIR to see a listing of your directory. The information that comes up on the screen will change according to the size and contents of your directory, but the following is a sample directory you can use for comparison:  
Type in DIR to see a listing of your directory. The information that comes up on the screen will change according to the size and contents of your directory, but the following is a sample directory you can use for comparison:  
 
 
[[image:2.5.png]]
[[image:2.5.png]]
 
Seeing the name GRANDMA has jogged your memory, and you now know that this is the file you wish to LOAD. Since the LOAD (LO) command automatically performs a CLEAR operation for you, you can simply enter LOAD GRANDMA (or LO GRANDMA), and your program will be loaded (but it will not be displayed).  
Seeing the name GRANDMA has jogged your memory, and you now know that this is the file you wish to LOAD. Since the LOAD (LO) command automatically performs a CLEAR operation for you, you can simply enter LOAD GRANDMA (or LO GRANDMA), and your program will be loaded (but it will not be displayed).  


Line 238: Line 227:
Eight optional parameters, when separated from the rest of the command with a space and a dash, can follow the DIR command (ex DIR -P).
Eight optional parameters, when separated from the rest of the command with a space and a dash, can follow the DIR command (ex DIR -P).
   
   
[[2.5.jpg]]
[[image:2.5.jpg]]


Try each of these to see the differences of what happens in each. Some of these options are completely ignored by Linux systems.  
Try each of these to see the differences of what happens in each. Some of these options are completely ignored by Linux systems.  
Line 264: Line 253:
1) The DIR command is used to:
1) The DIR command is used to:


a)  Print a listing of the files in a directory.  
a)  Print a listing of the files in a directory. <br>
b)  Direct the actions of a program.  
b)  Direct the actions of a program. <br>
c)  Load a file into memory.  
c)  Load a file into memory. <br>


2) The LOAD command automatically:  
2) The LOAD command automatically:  


a)  Starts Business Rules!.  
a)  Starts Business Rules!. <br>
b)  Loads a file and names it GRANDMA.  
b)  Loads a file and names it GRANDMA. <br>
c)  Performs a CLEAR operation and loads a program.  
c)  Performs a CLEAR operation and loads a program.<br>


Answers:
[[Answers 2.5]]
1-a; 2-c
 
 


Line 320: Line 309:
1) What does it mean to "scroll" the screen up or down?  
1) What does it mean to "scroll" the screen up or down?  


a)  Walk across the screen.  
a)  Walk across the screen. <br>
b)  Move program lines up or down the screen.  
b)  Move program lines up or down the screen. <br>
c)  Write program lines that go from the top to the bottom of the screen.  
c)  Write program lines that go from the top to the bottom of the screen. <br>


2) When you do not want to LIST an entire program before changing a line, you can just retype the line with the line number and press ENTER instead.  True or False?  
2) When you do not want to LIST an entire program before changing a line, you can just retype the line with the line number and press ENTER instead.  True or False? <br>


3) What happens when you forget to enter a line change with ENTER?  
3) What happens when you forget to enter a line change with ENTER? <br>


a)  Business Rules! makes the change anyway.  
a)  Business Rules! makes the change anyway. <br>
b)  The computer beeps and Business Rules! displays an error message.  
b)  The computer beeps and Business Rules! displays an error message. <br>
c)  Business Rules! does not make the change and keeps the original line.  
c)  Business Rules! does not make the change and keeps the original line. <br>


Answers:
[[Answers 2.6]]
1-b; 2-True; 3-c
 


===2.7 SAVE VS. REPLACE and FREE ===
===2.7 SAVE VS. REPLACE and FREE ===
Line 369: Line 356:
1) What information follows the REPLACE keyword?  
1) What information follows the REPLACE keyword?  


a)  The name of the programmer.  
a)  The name of the programmer. <br>
b)  The size of the file to be replaced.  
b)  The size of the file to be replaced. <br>
c)  The name of the file to be replaced.  
c)  The name of the program to be replaced. <br>


2) When Business Rules! replaces a file, it:  
2) When Business Rules! replaces a file, it:  


a)  Compares the new file to the old file and saves only the differences between the two.  
a)  Compares the new file to the old file and saves only the differences between the two. <br>
b)  Erases all the contents of the old file and replaces it with all the contents of the new file.  
b)  Erases all the contents of the old file and replaces it with all the contents of the new file. <br>
c)  Checks to be sure you are using a unique file name.  
c)  Checks to be sure you are using a unique file name.  


3) The SAVE command works only when:  
3) The SAVE command works only when:  


a)  You have executed your program at least three times.  
a)  You have executed your program at least three times.<br>
b)  The computer is hooked up to a modem.  
b)  The computer is hooked up to a modem. <br>
c)  You have specified a unique file name.  
c)  You have specified a unique file name. <br>


4) Which of the following is the proper command statement for deleting lines 102 through 237 of a program?  
4) Which of the following is the proper command statement for deleting lines 102 through 237 of a program?  


a)  DEL -102 237  
a)  DEL -102 237 <br>
b)  DEL 102 237  
b)  DEL 102 237 <br>
c)  DEL -102 -237  
c)  DEL -102 -237 <br>


Answers:
[[Answers 2.7]]
1-c; 2-b; 3-c; 4-b


====Challenge ====
====Challenge ====
Line 407: Line 393:


[[image:2.8.jpg]]
[[image:2.8.jpg]]
   
 
[[Solutions#CHAPTER 2|Solution]]


===2.8 External Editors ===
===2.8 External Editors ===
Many would consider using an external editor easier because navigation and functionality compares to programs such as Notepad or Microsoft Word. An external editor can be used to make editing Business Rules! programs simpler in many ways, including:
Using an external editor is recommended because it makes programming in BR much easier by allowing navigation and functionality that compares to programs such as Notepad or Microsoft Word. An external editor can be used to make editing Business Rules! programs simpler in many ways, including:
*Being able to use the cursor to access the point you want to edit in your program
*Being able to use the cursor to access the point you want to edit in your program
*no longer needing to hit Enter after editing a line
*no longer needing to hit Enter after editing a line
Line 417: Line 404:
*debugger feature (such as that in MyEdit external editor)
*debugger feature (such as that in MyEdit external editor)


For the purpose of this tutorial, you may use an external editor or work straight from Business Rules!, although as you develop increasingly complicated programs, you will find that an external editor saves a lot of time.  
For the purpose of this tutorial, you may use an external editor or work straight from Business Rules!, but as you develop increasingly complicated programs, you will find that an external editor saves a lot of time and reduces frustration.  
   
   
To install and use an external editor, a couple of concepts must be described first. There are two formats in which you can save a BR program:  
To install and use an external editor, a couple of concepts must be described first. There are two formats in which you can save a BR program:  
Line 461: Line 448:


====MyEditBR====
====MyEditBR====
MyEdit (BR edition) is an external editor available from Mills Enterprise. The program can be found at www.mills-enterprise.ca and the most complete documentation is located here.   
MyEdit (BR edition) is an external editor available from Mills Enterprise. The program can be found at [www.mills-enterprise.ca Mills Enterprise] and the most complete documentation is located [[MyEdit (BR Edition)|here]].   


MyEditBR includes the following features:
MyEditBR includes the following features:


Hints Warnings and Errors (HWE) - Built in checking for the most commonly encountered problems when moving from the standard BR editor to MyEditBR.  
*Standard text editing - edit your BR code with text editing techniques you probably already know and take for granted.
 
*Syntax Highlighting - Color coded syntax highlighting provides easy visual cues to program code.  
Syntax Highlighting - Color coded syntax highlighting provides easy visual cues to program code.  
*Code Completion - Provides quick shortcuts to long function names as well as showing the parameters of the current function.  
 
*Refactoring - The latest versions of the application support refactoring of variables, labels and named forms.
Code Completion - Provides quick shortcuts to long function names as well as showing the parameters of the current function.  
*BR Debugger - (requires BR! version 4.18 or higher) - Visual debugger, watches, breakpoints, conditional breakpoints (supported version only), hover-over tool tip, variable evaluation and more.  
 
*Re-mappable Keyboard Shortcuts - If you don't like a given keyboard shortcut, then change it!  
Refactoring - The latest versions of the application support refactoring of variables, labels and named forms.  
*Highly Customizable  - Persistent configuration changes between runs of the application. Includes window and tool window size, position storage, and configuration persistence.  
 
*Full Multi-Monitor Support - If you work on a laptop with an additional monitor at work but not at home, MyEditBR will always start up on the correct monitor.  
Line Renumbering - As powerful as BR but with additional capabilities.
 
BR Debugger - (requires BR! version 4.18+, where + means “or higher”) - Visual debugger, watches, breakpoints, conditional breakpoints (supported version only), hover-over tool tip, variable evaluation and more.  
Re-mappable Keyboard Shortcuts - Don't like a given keyboard shortcut, then change it!  
 
Highly Customizable  - Persistent configuration changes between runs of the application. Includes window and tool window size, position storage, and configuration persistence.  
 
Full Multi-Monitor Support - If you work on a laptop with an additional monitor at work but not at home, MyEditBR will always start up on the correct monitor.
 
Live Development  - New features can be added (or at least considered) on request.
 
Alt+Mouse Scrolling Changes Font Size - This is also implemented as keyboard shortcuts (Ctrl+Shift+< and Ctrl+Shift+>).  


====Lexi====
====Lexi====


Another helpful program is Lexi, which operates within MyEditBR to remove the need to enter line numbers while working on your program. Lexi will add the line numbers for you. Lexi also lets you use the SELECT CASE statement and the #DEFINE statement in Business Rules! For more information and instructions on installation visit [www.sageax.com/products/lexi Sage AX].
Another helpful program is Lexi, which operates within MyEditBR (or other editors) to remove the need to enter line numbers while working on your program. Lexi will add the line numbers for you. Lexi also lets you use the SELECT CASE statement and the #DEFINE statement in Business Rules!  
{{:Installing Lexi}}
For more information visit [www.sageax.com/products/lexi Sage AX].


NEXT: [[Chapter 3]]
NEXT: [[Chapter 3|More Operating and Programming Fundamentals]]


[[BR Tutorial|Back to Index]]
[[BR Tutorial|Back to Index]]
<noinclude>
[[Category:Tutorial 1]]
</noinclude>

Latest revision as of 13:55, 3 March 2019

2.1 Essential Commands

The information and exercises in this chapter will introduce you to the ground rules about managing Business Rules! programs. When you finish you will be able to :

  • Explain the difference between commands and statements.
  • Write commands and a short program using PRINT statements.
  • Use commands to CLEAR, RUN, LIST, SAVE, LOAD, and REPLACE Programs.
  • Print a directory listing using the DIR command
  • Recognize and respond to an error message.
  • Edit program lines.

Instead of starting you off with lots of boring stuff about programming theory, we're going to cheat a little and skip ahead to the fun part, writing commands and program statements with Business Rules!. First we will teach you the abilities of the PRINT command.

Commands VS Statements

As soon as you type in a command and push ENTER, the computer executes it. A Business Rules! statement is also an instruction to the computer, but it occurs in a list of instructions (a program) which aren't executed until you say they should be with the RUN command. Keep in mind that any statement can be run as a command.

You should be sitting in front of your computer right now, with Business Rules! loaded and READY for you to begin (to start up Business Rules!, read the instructions in Chapter 1).

Are you ready? Okay, start by typing in:

PRINT 6+4 

When you've got that done, press ENTER. The computer will respond immediately and your screen should now say:

PRINT 6+4 
10 

Yes, among its many fine features, Business Rules! also operates as a calculator! You have just used the PRINT command to tell Business Rules! to perform a mathematical operation and print the result on the screen. In fact the word PRINT is assumed if any expression is entered without any command.

Try entering:

6+4 

Feel free to experiment, right now, using Business Rules! as a calculator. If you wish to use multiplication or division in you calculations, you should use * for the multiplication symbol and / for the division symbol. Business Rules! uses standard algebraic rules to determine the precedence of mathematical functions (i.e., multiplication and division take precedence over addition and subtraction).

Quick Quiz 2.1

1) Match the following:

a) Command 1) Executed immediately
b) Statement        2) Requires a line number, executed when the program is run.

2) When PRINT is followed by a mathematical operation, such as PRINT 8 * 4, it performs like:

a)   A calculator.
b)   The square root sign.
c)   A typewriter.

3) How would Business Rules! compute the following mathematical problems? Figure them out first by hand, then use PRINT to check your answers:

a)  2+8*6
b)  (3+4)/2
c)  5*5+82-63/3+13

Answers 2.1  

2.2 Using PRINT with delimiters

You have used the PRINT command to print the results of a mathematical operation, but PRINT can also be used to print words, phrases, numbers and numeric formulas. When you want Business Rules! to print something exactly as you have written it, you must enclose it in single or double quotation marks. Try typing in the following command:

PRINT “6+4”

The quotation marks are called “delimiters”. As soon as you press ENTER, the screen should look like this:

PRINT "6+4" 
6+4 

Now try typing in this:

PRINT 'single quotes are delimiters too' 

Business Rules! will print letters, spaces, and almost any symbol that is on your keyboard when you enclose them in either double ( " " ) or single ( ' ' ) quotation marks.  

Quick Quiz 2.2

1) When used with PRINT, delimiters are:
a)  Lines that mark the beginning and end of a program.
b)  Symbols that mark the beginning and end of information to be printed.
c)  Symbols that tell Business Rules! to ignore the current command.

2) True or False - PRINT prints quotation marks when you use them as delimiters, for example, PRINT "Greetings, Earthlings"

3) Which of the following pairs of symbols can be used as delimiters with PRINT?
a)  & &
b)  * #
c)  " "
d)  " '
e)  ' '

Answers 2.2

2.3 Getting your first ERROR

You might know that falling properly is one of the first things you learn when you take martial arts. Well, learning to fall is important when it comes to programming too, but in this case it's called getting an error.

Sending error messages is Business Rules! way of telling you that it doesn't understand your instructions. Since Business Rules! has a much smaller vocabulary than you do and since Business Rules! requires you to present command or statement information in a very specific order you may frequently find yourself getting error messages.

Don't worry! Error messages are a frequent occurrence even for the most experienced programmers. For you, the student, error messages can become a valuable part of the learning experience which tell you about what BR expects you to do.

To get your first error, try typing in the following:

PRINT "Hi

Notice the end quote is missing, and this results in an error. Now press ENTER. Your computer should respond with an obnoxious beep. If you look in the status line on the bottom row of the screen you will see the word ERROR in the left corner and the number 1003 in the center.

The number is the error code and identifies the type of error which occurred. Typing in BRERR$(1003) will show you the error message. If an error does occur, then you can search the wiki by error number in order to find its meaning and possible solutions. (Always search for error numbers using four digits, i.e. if it’s error 745, search for 0745).

"Missing quote" is the description for error 1003. Looking back at the command, you can see that this error happened because you didn't include the ending quotation mark or delimiter that tells Business Rules! to print the information between it and the beginning delimiter exactly as it appears.

You can correct the command by using your arrow keys to move the cursor to the end of the line, and then adding the quotation mark right after the exclamation point. The correct command should look like this:

PRINT "Hi!" 

Quick Quiz 2.3

1) You will receive ERROR messages when:

a)  You tilt your computer.
b)  Business Rules! doesn't understand your instructions.
c)  Business Rules! just doesn’t like you.

2) An error code is:

a)  The word ERROR in your status line.
b)  A series of beeps which identify the type of error which occurred.
c)  A number which identifies the type of error which occurred.

3) Where can you find a listing of the different Business Rules! error codes and their meanings?

a)  At the end of this chapter.
b)  In the Error Handling chapter.
c)  On the Internet at brwiki.brulescorp.com, by typing the error code into the search engine.

Answers 2.3

2.4 Writing a program

In previous sections you saw how PRINT can be used as a command to immediately print words, numbers or mathematical results. As you will see in this lesson, PRINT operates the same way when used as a statement in a program.

With Business Rules! loaded and READY, type in the following (always press ENTER after each line):

CLEAR

This command clears any programs or stray program lines which may be in the computer’s temporary memory.  You should get into the practice of using this command every time you begin writing a new program. If you wish to also clean off the screen, type in

NEWPAGE

Now type the following lines exactly as they appear:       

If you get an error, or if you make a typing mistake, you can use the arrow keys to reposition the cursor and type the information correctly. Remember to always press ENTER after each line. If you notice a typing mistake after you've already finished typing a line and pressed ENTER, just retype the entire line (don't forget the line number).

Business Rules! will automatically replace the old one with the new one and put it in the right order for you.

The STOP (STO) statement in line 60 simply tells the system to stop executing the program at this line. Since you are already familiar with PRINT, you can probably guess what lines 10-50 will do when this program is executed--but let's try it anyway. RUN is the command that you use to execute a program. Type RUN or (RU), then press ENTER.

The computer should respond, and the lower portion of your screen should now say:

You can type RUN and press ENTER to re-execute your current program.

To see your program lines again, you can type LIST. The computer should respond with:

Hey! Business Rules! changed your program!

Your line numbers are now five digits long instead of two, and your statement keywords are now in uppercase instead of lowercase. Business Rules! automatically makes these changes to every program line that you enter. As you go through the rest of this tutorial, you will learn about keyword abbreviations and other typing shortcuts that you can use, but Business Rules! will always LIST your programs in its own preferred format.

This has been a long lesson and you may be thinking that it's time for a break. If you exit Business Rules! now, you will lose the program you just wrote along with all the time and effort you put into typing it. To avoid such a grim occurrence, first SAVE the program to a file. To do this, type:

SAVE GRANDMA 

The name that you gave it, GRANDMA, is the same name you will use when you wish to recall the program from memory with the LOAD command (which you'll learn about in the next chapter).

You can now type SY or SYSTEM to exit Business Rules!, or you can type NEWPAGE, and go on to the next lesson.

Quick Quiz 2.4

1) Match the following:

a. STOP (STO) 1. Stores a program on disk.
b. RUN (RU) 2. Terminate program execution.
c. LIST (LIS) 3. Exits Business Rules!.
d. SAVE (SA) 4. Shows program lines.
e. SYSTEM (SY) 5. Executes a program.

2) What are two changes that Business Rules! makes to your program lines before it LISTs them?

a)  Fixes all spelling errors.
b)  Changes lowercase letters to uppercase.
c)  Increments every line number by ten.
d)  Lengthens all line numbers to five digits.
e)  Makes every line the same length.

3) What should you always do before exiting Business Rules!?
a)  Log out.
b)  Save any programs or data you wish to keep.
c)  Use the CLEAR command to remove all information from temporary memory.

Answers 2.4

2.5 DIR & LOAD command

In the last lesson, you learned how to write a program with PRINT statements, edit it, and then SAVE it. Now let's learn how to find that program in your directory and LOAD it back into your computer’s memory.

Imagine that you have forgotten the name of the file that you saved in the last lesson. If you could just see a list of the files in the computer's memory, you know you would recognize the name. The DIR command lists the names of all the files in the directory. DIR also gives you other information about your files and directories.   Type in DIR to see a listing of your directory. The information that comes up on the screen will change according to the size and contents of your directory, but the following is a sample directory you can use for comparison:

Seeing the name GRANDMA has jogged your memory, and you now know that this is the file you wish to LOAD. Since the LOAD (LO) command automatically performs a CLEAR operation for you, you can simply enter LOAD GRANDMA (or LO GRANDMA), and your program will be loaded (but it will not be displayed).

When your program is loaded, READY will appear in the status line. The name of your program will be in the Program Name section of the Status Line. Type NEWPAGE. You can now RUN or LIST the program.   Eight optional parameters, when separated from the rest of the command with a space and a dash, can follow the DIR command (ex DIR -P).  

Try each of these to see the differences of what happens in each. Some of these options are completely ignored by Linux systems.

-A Displays directory information about files with the archive bit on. The archive bit automatically sets to "on" whenever a file is changed. The operating system's back-up utility or the -A option of the COPY command turns it off (see COPY command).
-L Lists the permissions for each file on Linux versions.
-O Sorts the directory output in alphabetical order.
-P Causes scrolling to pause after a full screen of information has been displayed (press ENTER for next screen).
-W Sorts the output and displays names in four columns across the width of the screen.
-C Prints in a list of files/programs in sorted columns with a trailing / symbol for directories and trailing * for executables. 
-L Displays long filenames in addition to the normal DOS style directory.
-D Displays only the bare long filename, similar to DOS.

Quick Quiz 2.5

1) The DIR command is used to:

a)  Print a listing of the files in a directory.
b)  Direct the actions of a program.
c)  Load a file into memory.

2) The LOAD command automatically:

a)  Starts Business Rules!.
b)  Loads a file and names it GRANDMA.
c)  Performs a CLEAR operation and loads a program.

Answers 2.5

 

2.6 Editing program lines

Now let's imagine that you are tired of the sentence that the program GRANDMA prints and that you would like to change it. After all, Grandma Mary looks very out of place wearing a black leather jacket and playing her electric guitar at a nice June wedding.   There are two ways to edit program lines. First, you can simply retype a line which is already in the program. Business Rules! will replace the old one with your new version. Let's try this method by replacing line 50 with the following:  

00050 PRINT "rock concert." 

Now type NEWPAGE, press ENTER, and RUN the program. The screen should read:

Grandma Mary 
played 
her electric guitar 
at the 
rock concert. 

  This first editing method works fine, but often you will want to see the program lines as you edit them. Also it is easier to change program lines than to retype them. The LIST command allows you to list the lines in a program, then use the second editing method. Type LIST, then press ENTER.   Since you still are not satisfied with the sentence as it appears, make another change to it using this direct editing method. Can you make grandma play an accordion instead of a guitar? Move the cursor to the first "e" in "electric guitar" in line 00030. Type the word "accordion" directly over it and push your delete key until the extra letters disappear. The line should now look like this:  

00030 PRINT "her accordion" 

Do not move the cursor to line 20 or to any other line before pushing ENTER. If you do, line 30 will not be changed in memory. Pressing ENTER causes your changes to be entered into Business Rules!'s memory. The cursor will rest on the next line, and the bottom portion of your screen will look like this:  

00010 PRINT "Grandma Mary" 
00020 PRINT "played" 
00030 PRINT "her accordion" 

You can now move the cursor back to line 30 or any line above or below it to make other changes or you can LIST or RUN the entire program again. If you have made the changes that we've suggested here, a RUN of the program would look like this:  

Grandma Mary 
played 
her accordion 
at the 
rock concert 

NOTE: You cannot edit your program if you RUN it after you LIST it, and then move your cursor back up to the program lines before the RUN command to change them. This is because after the program is in RUN mode, you cannot change anything (the memory is not affected) and anything that goes off of the screen when you scroll is erased from the screen. You must LIST the program again first.   Leave this program as it is for the "SAVE VS. REPLACE and FREE" section, up next after a quick quiz.  

Quick Quiz 2.6

1) What does it mean to "scroll" the screen up or down?

a)  Walk across the screen.
b)  Move program lines up or down the screen.
c)  Write program lines that go from the top to the bottom of the screen.

2) When you do not want to LIST an entire program before changing a line, you can just retype the line with the line number and press ENTER instead.  True or False?

3) What happens when you forget to enter a line change with ENTER?

a)  Business Rules! makes the change anyway.
b)  The computer beeps and Business Rules! displays an error message.
c)  Business Rules! does not make the change and keeps the original line.

Answers 2.6

2.7 SAVE VS. REPLACE and FREE

You now have two versions of GRANDMA. Your original version is in permanent (disk) storage, and your edited version is in temporary memory (you can view it on the screen when you type in the LIST command, but it has not been saved). Normally when you are in this position you will want to replace the original copy of the program with the new one. So, since GRANDMA is already loaded, and you have made changes on temporary memory, you may simply type in the REPLACE command (REP). If you ever want to REPLACE a program that is not loaded, type the REP command and the name of the program (i.e. REP GRANDMA). If you look in your directory and the program you're looking for has a different suffix than the usual ".br", you must type in REP and the full name including the suffix (ex: REP GRANDMA.BAK).

REP GRANDMA 

REPLACE tells Business Rules! to save the file currently in memory, and GRANDMA is the name of the file that you told it to replace. When Business Rules! executes this command, it erases all the contents of the old file and gives the name GRANDMA to the contents of the new file. The old GRANDMA that you first made will become grandma.bak. This is a backup of your first version of the program. If you type in LOAD (LO) grandma.bak, you will load the program that was saved under this name before you replaced it. Deleting a backup program is not necessary, but if you want to, type in "FREE grandma.bak" and it will be removed from your directory.

FREE GRANDMA.BAK

The FREE command is the opposite of the SAVE command. It deletes a program from your directory. For any program that is a ".br" file or a ".wb" file, you may simply type in the name of the program after LOAD or FREE. But if it has any other suffix, i.e. ".bak" (which is a backup of a replaced program), you must type in the name and the suffix. ex: FREE grandma.bak. If you type in FREE, the program name, and then press ENTER, the next line will show the location of the file that you just deleted.   Business Rules! programmers sometimes make the mistake of trying to use SAVE when they really mean to use REPLACE. Since the two commands perform similar functions, this is an easy error to make (error 4150 - use of duplicate file name).   Every time you SAVE a file, Business Rules! checks to be sure that you are using a unique file name. If another file by the name you specify already exists, Business Rules! displays an error message. There are no exceptions to this rule. SAVE works only when you specify a brand new, unique file name.   When you use the REPLACE command however, Business Rules! assumes that you want to replace the contents of a file which already exists with new information. This is the command that you use when you want to re-save an old program with an edited or revised version.  

DEL Command

Editing program lines is an important ability, but what if you need to get rid of a certain program line for good? This is the purpose of the DELETE command. "DE" makes this command unique, so any letters after these are optional. The delete command eliminates the program line, or group of program lines, that you specify. However, remember that any changes to a program will not be saved to your hard drive until you SAVE or REPLACE your current program. Go ahead and practice this command by deleting line 50 of GRANDMA before reading ahead (which explains how to do it).

Please LOAD GRANDMA if it is not already loaded, then LIST it. Type in "DEL 50" and press ENTER. Then LIST the program again. Line 50, including the print statement "rock concert" will be missing. Do not replace GRANDMA.

This is how to delete a single program line. Notice that when you LIST the program, it shows Line 60 just below Line 40. It is ok for line numbers to jump like this, but we will tell you how to renumber lines in a later chapter anyway. Now type the following: "DEL 20 60", then press ENTER. Then LIST the program. Lines 20 through 60 have just been deleted, and only line 10 remains.

So, to delete a group of lines, you type in the DEL commands, then the starting line number to delete, a space, and then the ending line number to delete. These are the two parameters for DEL (starting line, ending line). The ending line parameter is optional -- if you don’t give it a value, DEL will simply delete the starting line.

Quick Quiz 2.7

1) What information follows the REPLACE keyword?

a)  The name of the programmer.
b)  The size of the file to be replaced.
c)  The name of the program to be replaced.

2) When Business Rules! replaces a file, it:

a)  Compares the new file to the old file and saves only the differences between the two.
b)  Erases all the contents of the old file and replaces it with all the contents of the new file.
c)  Checks to be sure you are using a unique file name.

3) The SAVE command works only when:

a)  You have executed your program at least three times.
b)  The computer is hooked up to a modem.
c)  You have specified a unique file name.

4) Which of the following is the proper command statement for deleting lines 102 through 237 of a program?

a)  DEL -102 237
b)  DEL 102 237
c)  DEL -102 -237

Answers 2.7

Challenge

You write a program and SAVE it, then make changes to it. You now have the saved program in permanent storage and the edited program in temporary memory. What should you do if you wish to keep both versions?

Answer: Save the edited program under a new name. You can then access the original file with the original name and the updated version with the new name.

Chapter Exercise

1) Write a 10-line program to print the numbers from 1 to 10.

2) Write a program to print a large box made of asterisks, with your name in the middle of the box. Your output should look something like this:

Solution

2.8 External Editors

Using an external editor is recommended because it makes programming in BR much easier by allowing navigation and functionality that compares to programs such as Notepad or Microsoft Word. An external editor can be used to make editing Business Rules! programs simpler in many ways, including:

  • Being able to use the cursor to access the point you want to edit in your program
  • no longer needing to hit Enter after editing a line
  • using text editing features such as copy and paste, spell checker, etc.
  • using custom highlighters, which use various colors to differentiate between variable types, keywords, comments, etc. This makes programs more readable.
  • debugger feature (such as that in MyEdit external editor)

For the purpose of this tutorial, you may use an external editor or work straight from Business Rules!, but as you develop increasingly complicated programs, you will find that an external editor saves a lot of time and reduces frustration.

To install and use an external editor, a couple of concepts must be described first. There are two formats in which you can save a BR program:

  1. in BR format similar to binary format, and
  2. as source which is in plain text format

To save a program in BR format, simply type in

save program_name.wb 

or

save program_name.br

where program_name is the name you want to assign to your program. Both .br and .wb are valid extensions for BR programs. The default extension is .br, so if you type in save program_name, the .br extension will be used.

To save a program as source, type:

save program_name source

The default extension for source files is .brs, but .wbs may be used if desired. Source format is necessary if you want to use an external editor.

In order to load a program from source into the BR environment, type in load program_name source. At this point BR takes the text version of your program, converts it to BR format, and loads it into the BR environment.

Another requirement prior to using an external editor is specifying which editor you will be using. This is done by putting an EDITOR statement into your configuration file wbconfig.sys using a full path to your editor. Here is an example of an EDITOR statement:

EDITOR "C:\Program Files (x86)\Mills Enterprise\MyEditBR\MyEditBR.exe"

To make a file editable in any text editor, 1. save the program as source 2. load it from source 3. use the EDIT command

The EDIT command does the following:

  1. Lists the currently loaded program to a source file
  2. Calls a text editor, which opens the source file
  3. After you save the changes in the text editor, pressing Enter in your BR window merges the changed lines into the program.

Other ways to put a BR program into source code include:

  1. LIST >path\filename.BRS
  2. SAVE path\filename.BRS,source 
  3. REPLACE path\filename.BRS,source 
  4. BR2BRS (this is a batch utility documented further here)

Keep in mind that the external editor you use may have alternate methods for getting the program out of and back into Business Rules! A list of commonly used external editors can be found here.

MyEditBR

MyEdit (BR edition) is an external editor available from Mills Enterprise. The program can be found at [www.mills-enterprise.ca Mills Enterprise] and the most complete documentation is located here

MyEditBR includes the following features:

  • Standard text editing - edit your BR code with text editing techniques you probably already know and take for granted.
  • Syntax Highlighting - Color coded syntax highlighting provides easy visual cues to program code.
  • Code Completion - Provides quick shortcuts to long function names as well as showing the parameters of the current function.
  • Refactoring - The latest versions of the application support refactoring of variables, labels and named forms.
  • BR Debugger - (requires BR! version 4.18 or higher) - Visual debugger, watches, breakpoints, conditional breakpoints (supported version only), hover-over tool tip, variable evaluation and more.
  • Re-mappable Keyboard Shortcuts - If you don't like a given keyboard shortcut, then change it!
  • Highly Customizable - Persistent configuration changes between runs of the application. Includes window and tool window size, position storage, and configuration persistence.
  • Full Multi-Monitor Support - If you work on a laptop with an additional monitor at work but not at home, MyEditBR will always start up on the correct monitor.

Lexi

Another helpful program is Lexi, which operates within MyEditBR (or other editors) to remove the need to enter line numbers while working on your program. Lexi will add the line numbers for you. Lexi also lets you use the SELECT CASE statement and the #DEFINE statement in Business Rules! BR programs are much easier and faster to edit if you're using an External Editor, such as MyEditBR, that has Lexi installed. Lexi is a BR lexical pre-processor which allows you to edit programs without line numbers.

Lexi can be installed in MyEditBR with these simple steps:

  1. ) Download LEXI from SageAX.
  2. ) Unzip Lexi.zip into "C:\Lexi". You must use this directory in order for the automatic installation to work.
  3. ) Copy your own brserial.dat file into this directory (C:\Lexi).
  4. ) Launch MyEdit.
  5. ) Select Tools -> Configure User Tools from the menu, and click the Import Tools button. Select the "Lexi.mut" file that came in Lexi.zip.

Installing Lexi in Notepad++.

Installing Lexi in Sublime. For more information visit [www.sageax.com/products/lexi Sage AX].

NEXT: More Operating and Programming Fundamentals

Back to Index