Please enable JavaScript to view this site.

R:BASE 11 Beginners Tutorial

Navigation: Lesson 8 - Writing Command Files

Designing And Writing A Command File

Scroll Prev Top Next More

Command files generally perform the same tasks you do by typing in commands at the R> Prompt. The major difference is that a command file saves the sequence of commands so that they can be repeated by you or someone else, such as a data-entry operator. For example, suppose you want to provide an option for the operator to check the total transaction amount for the current date.

 

In the following steps, you will learn how to enter the command file using the R:BASE Editor, and how to execute the command file outside of an application structure.

 

1.On line 1, within the RBEDIT screen, enter the SELECT command like this:

 

SELECT SUM(TotalCharge) FROM Flights WHERE FlightDate = 08/12/2022

 

You need not enter upper and lower case as shown in the examples.

 

This command calculates the sum of the total charges column (TotalCharge) for flights performed whose date (FlightDate) is 08/12/2022. The command compares the value of FlightDate to the date value 08/12/2022 and, if they match, includes the value in the sum for the column TotalCharge.

 

2.Now save the file. To do so, you have several options. You can choose File: Save from the main menu bar, click on the blue diskette icon on the R:BASE Editor toolbar, or use the hot keys [Ctrl]+[S].

 

RBEDIT asks for a name for the new file within a "Save As" dialog window.

 

3.Within the "File name:" field, type ChargesByDateRange.rmd
4.Within the "Save as type:" field, select the "RMD Files (*.rmd)" option.
5.Click on the "Save" button.

 

Next, you are going to switch from the "R:BASE Editor" window to the "R> Prompt" window. By now you may have seen the button for each opened module across the bottom of the R:BASE program. Right now, you may see buttons for the "Database Explorer, the "R:BASE Editor", and the "R> Prompt" window.

 

6.Choose the "R> Prompt" button to move the focus to the "R> Prompt" window.

 

Now you can try out your program using the RUN command.

 

7.At the R> Prompt, enter: RUN ChargesByDateRange.rmd

 

The command file displays the total of the transactions entered on 08/12/2022 - $2,650.00.

 

What can be done to enhance this program to make it more useful and meaningful for anyone using the application? First, consider whether you want to execute this program from a menu. If so, you may want to display a message to the operator along with the total. In this case, you can enhance the SELECT command to place the total in a variable.

 

8.To edit the program again, choose the "R:BASE Editor" button to move the focus to the "R:BASE Editor" window
9.Position the cursor on the F in the word FROM. Enter the words "INTO vSum" and add a space.

 

The command file now looks like this:

 

SELECT SUM(TotalCharge) INTO vSum FROM Flights WHERE FlightDate = 08/12/2022

 

This creates a variable vSum to hold the sum computed by the command.

 

10.Press the [End] key to place the cursor at the end of the line, then [Enter] to move the cursor to the next line.

 

11.For the second and third lines, enter:

 

SET VAR vMessage TEXT = ('The total for 08/12/2022 is: ' + (CTXT(.vSum)))

PAUSE 2 USING .vMessage CAPTION 'Sum' ICON INFO

 

When R:BASE executes the command file, these lines display a message box with the text "The total for 08/12/2022 is: $2,650.00", with the word "Sum" in the dialog caption, and an "Info" icon. The default text for the button will be"OK", but even that can be changed.

 

The SET VAR command creates a TEXT variable vMessage that combines two portions of the displayed message. The first portion defines the actual text "The total for 08/12/2022 is: ". The second portion contains the vSum variable within the CTXT Function. From the previous lesson, Functions were described to be used within R:BASE to perform a series of set calculations or convert values into other forms. The CTXT is an example of a Function that converts a value into another form. The CTXT Function takes the .vSum variable, which is defined as a CURRENCY data type from the TotalCharge column, and converts it to a TEXT data type within the SET VAR command. The vSum variable needed to be converted to TEXT as you cannot combine values with TEXT and CURRENCY data types. The data types must match, or must at least be compatible (e.g. DOUBLE and INTEGER).

 

Since this command file is to be executed as a menu option, The PAUSE 2 command will give the operator some time to look at the total before returning to the menu display, until a key is pressed.

 

12.Finally, you want to return to the menu. Enter this line as line 4 in the command file:

 

RETURN

 

The entire command file looks like this:

 

SELECT SUM(TotalCharge) INTO vSum FROM Flights WHERE FlightDate = 08/12/2022

SET VAR vMessage TEXT = ('The total for 08/12/2022 is ' + (CTXT(.vSum)))

PAUSE 2 USING .vMessage CAPTION 'Sum' ICON INFO

RETURN

 

13.Now save the file. To do so, you have several options. You can choose File: Save from the main menu bar, click on the blue diskette icon on the R:BASE Editor toolbar, or use the hot keys [Ctrl]+[S].

 

14.Close the R:BASE Editor window by choosing   File: Close File from the main menu bar, clicking on the "Close File" icon on the toolbar, or by pressing the lower "x" on the top right corner. If you use hot keys, you can press [Ctrl]+[F4].