Rexx – Graphical User Interface ”; Previous Next In order to use the graphic user interfaces available in Rexx, one needs to use 2 packages, one is called ActiveTcl and the other is the Rexxtk package. Along with these 2 packages, one can design normal forms which can have buttons and other controls on the forms. Environment Setup The first thing to do is the environment setup. Let’s go through the following steps to have the environment in place. Step 1 − Download the Activetcl package from the following website − https://www.activestate.com/activetcl Step 2 − The next step is to start the installation of ActiveTCl. Click on the Next button on the screen to proceed. Step 3 − Accept the license Agreement and click on the Next button. Step 4 − Choose a location for the installation and click on the next button. Step 5 − Choose a location for the installation of the demo’s and click on the Next button. Step 6 − Click on the Next button to proceed with the installation. Step 7 − Click on the Finish button to complete the installation. Step 8 − The next step is to download the Rexxtk software from the following link − https://sourceforge.net/projects/rexxtk/ Step 9 − Double click the installer file from the link in the previous step to start the installation. Click on the next button to proceed. Step 10 − In the next screen, click on the Yes button to agree to the License Agreement. Step 11 − In the next screen, choose the location for the installation and click on the Next button. Step 12 − Choose the Program folder location and click on the next button. Once the installation is complete, we can now start with programming the GUI’s in Rexx. Basic Program Let’s see how we can design a simple basic program with Rexx in a graphical user interface format. Example /* Main program */ call RxFuncAdd ”TkLoadFuncs”,”rexxtk”,”TkLoadFuncs” call TkLoadFuncs do forever interpret ”Call” TkWait() end call TkDropFuncs exit 0 The following things need to be noted about the above program − The Rexxtk library and all of its functions are loaded using the RxFuncAdd command. The do forever loop will keep the window open and will wait for the user input. Once the user input is detected, the program will exit. When the above program is executed, you will get the following output. Creating Menus Menus are created with the help of the TkMenu and TkAdd functions. The syntax of these functions are given below. Syntax TkMenu(widgetname,options,0) Parameters Widgetname − A name to give to the menu. Options can be anyone of the following − selectcolor − if checkboxes or radio buttons are used as menu options, then this option specifies the color to choose when any menu option is selected. tearoff − This option is used for adding sub menus to the main menu. title − The string that needs to be used to give the window a title. Return Value A handle to the menu created. Example /* Main program */ call RxFuncAdd ”TkLoadFuncs”,”rexxtk”,”TkLoadFuncs” call TkLoadFuncs menubar = TkMenu(”.m1”) filemenu = TkMenu(”.m1.file”,”-tearoff”, 0) call TkAdd menubar, ”cascade”, ”-label”, ”File”, ”-menu”, filemenu call TkAdd filemenu, ”command”, ”-label”, ”Open…”, ”-rexx”, ”getfile” call TkConfig ”.”, ”-menu”, menubar do forever interpret ”Call” TkWait() end call TkDropFuncs exit 0 The following things need to be noted about the above program − The menubar is created using the TkMenu function. The ‘tearoff’ parameter means that we need to create sub menus which is going to be attached to the main menu. We then add 2 menu options called File and Open using the TkAdd function. When the above program is executed, you will get the following output. Print Page Previous Next Advertisements ”;
Category: rexx
Handheld & Embedded
Rexx – Handheld & Embedded Programming ”; Previous Next Handheld devices have come a long way and Rexx has a lot of ways in which it can run on these devices. Rexx has support for Pocket PC’s, Palm devices, PDA’s and other smart phone devices. The advantage of Rexx to work on these platforms is that Rexx is really a small weight programming system which just runs in the span of a few kilobytes. Hence it becomes easier to run Rexx programs on these devices. Rexx on hand-held devices can run in the following modes − The first mode is the native node where it runs directly on the operating system itself. The advantage on running in this mode is that it is faster since it runs directly off the operating system. The next mode is on top of the DOS or emulator program on top of the hand held device. The advantage of this mode is that is can run on any type of operating system as long as the emulator runs on that operating system. The Rexx Interpreters for the various hand held devices categories are shown below. Windows CE − Brexx Palm OS − Rexx for Palm OS Symbian OS − Regina For the DOS emulator, the following steps need to be carried out − Step 1 − First is to download PocketDOS which is a popular DOS emulator. It is designed to run on many operating systems and has support for common VGA screens and serial and parallel ports. Step 2 − The next step is to download the BRexx files for 16-bit DOS to a Windows PC. Step 3 − The final step is to use ActiveSync to sync the Rexx program to the hand held device. There are some other commercial DOS based products available. XTM is a product which falls under this category. The features of this product are as follows − Support for the 80186 CPU and instruction set. It kind of works off the BIOS code for better performance. It can provide emulation for the Math co-processor, version 8087 MPU It provides access to the serial ports. It supports a variety of languages such as English, French and German. Print Page Previous Next Advertisements ”;
Rexx – Databases
Rexx – Databases ”; Previous Next Rexx has the ability to work with a variety of databases which are listed below. HSQLDB Oracle SQL Server MySQL MongoDB All the information for Rexx databases can be found once you click on the following link − https://rexxsql.sourceforge.net/ In our example, we are going to use MySQL DB as a sample. So the first step is to ensure to download the required drivers from the Rexx SQL site so that Rexx programs can work with SQL accordingly. So follow the subsequent steps to ensure that Rexx programs can work with MySQL databases. Step 1 − Go to the following drivers download page from the Rexx site − https://sourceforge.net/projects/rexxsql/files/rexxsql/2.6/ Step 2 − Download the MYSQL drivers – rxsql26B3_my_w32_ooRexx Step 3 − Unzip the contents to the local machine. Step 4 − Add the path of the unzipped folder to the path variable on your machine. For all the subsequent examples, make sure of the following pointers are in place − You have created a database TESTDB. You have created a table EMPLOYEE in TESTDB. This table has fields FIRST_NAME, LAST_NAME, AGE, SEX and INCOME. User ID “testuser” and password “test123” are set to access TESTDB. Ensure you have downloaded the mysql jar file and added the file to your classpath. You have gone through MySQL tutorial Database Connection To establish a database connection, you first need to the Rexxsql DLL and then use the SQLConnect function to establish a connection to the database. The syntax and example of how this can be achieved is given below. Syntax SQLConnect(cname,username,password,dbname) Parameters cname − This is the name to give to the connection. username − The user name to connect to the database. password − The password to connect to the database. dbname − The database schema to connect to. Return Value A value equal to 0 will mean that the database connection is successful. Example /* Main program */ Call RxFuncAdd ”SQLLoadFuncs”, ”rexxsql”, ”SQLLoadFuncs” Call SQLLoadFuncs say SQLConnect(c1,” testuser ”,” test123”,”testdb”) The output of the above program would be as shown below. 0 Creating a Database Table The next step after connecting to the database is to create the tables in our database. The following example shows how to create a table in the database using Rexx. All of the commands in Rexx SQL are executed by using the SQLCommand function. Syntax SQLConnect(sname,statement) Parameters sname − This is the name to give to the statement to execute. statement − This is the statement which needs to be executed against the database. Return Value A value equal to 0 will mean that the command was successful. Example /* Main program */ Call RxFuncAdd ”SQLLoadFuncs”, ”rexxsql”, ”SQLLoadFuncs” Call SQLLoadFuncs if SQLConnect(c1,”testuser”,”test123”,”testdb”) == 0 then say ”Connect Succedded” if SQLCommand(u1,”use testdb”) == 0 then say ”Changed database to testdb” sqlstr = ”create table employee (first_name char(20) not null, last_name char(20),age int, sex char(1), income float)” if SQLCommand(c2,sqlstr) == 0 then say ”Employee table created” The output of the above program would be as shown below. Connect Succedded Changed database to testdb Employee table created Operations on a Database Table The following types of operations are most commonly performed on a database table. Sr.No. Operation & Description 1 Insert Operation It is required when you want to create your records into a database table. 2 Read Operation A READ Operation on any database means to fetch some useful information from the database. 3 Update Operation The UPDATE Operation on any database means to update one or more records, which are already available in the database. 4 Delete Operation The DELETE operation is required when you want to delete some records from your database. 5 Closing a Connection The following command can be used to close a connection to the database. Performing Transaction Transactions are a mechanism that ensures data consistency. Transactions have the following four properties − Atomicity − Either a transaction completes or nothing happens at all. Consistency − A transaction must start in a consistent state and leave the system in a consistent state. Isolation − Intermediate results of a transaction are not visible outside the current transaction. Durability − Once a transaction was committed, the effects are persistent, even after a system failure. Here is a simple example of how to implement transactions. Example /* Main program */ Call RxFuncAdd ”SQLLoadFuncs”, ”rexxsql”, ”SQLLoadFuncs” Call SQLLoadFuncs if SQLConnect(c1,”testuser”,”test123”,”testdb”) == 0 then say ”Connect Succedded” if SQLCommand(u1,”use testdb”) == 0 then say ”Changed database to testdb” sqlstr = “DELETE FROM EMPLOYEE WHERE AGE > 20″ if SQLCommand(c2,sqlstr) == 0 then if sqlcommit() == 0 then say committed The output of the above program would be as shown below. Connect Succedded Changed database to testdb COMMITTED Commit Operation The commit operation is what tells the database to proceed ahead with the operation and finalize all changes to the database. In our above example, this is achieved by the following command. Sqlcommit() Rollback Operation If you are not satisfied with one or more of the changes and you want to revert back those changes completely, then use rollback method. In our above example, this is achieved by the following command. SqlRollback() Print Page Previous Next Advertisements ”;
Rexx – Instructions
Rexx – Instructions ”; Previous Next Rexx provides a number of instructions that gives a wide variety of functionality, most of them which allow you to interact with the Operating System. Let’s look at some of them in detail. Sr.No. Rexx Instructions 1 address This function is used to display the current command environment. 2 drop This function is used to un-assign a variable. 3 interpret Interprets or executes the defined instruction. 4 nop This function means to perform no operation. This command is normally used in if statements. 5 Pull This is used to pull input from the stack or from the default stream. 6 push This is used to push a value onto the Rexx stack. Print Page Previous Next Advertisements ”;
Rexx – Portability
Rexx – Portability ”; Previous Next Portability is an important aspect in any programming language. As one knows, Rexx is available in a variety of operating systems such as Windows and Linux. So it need to be ensured that when one develops a program on the Windows platform, that it has the necessary precautions taken if the same programs runs on a Linux platform. Rexx has the ability to run system level commands. There are commands which can be used to understand what is the operating system on which it is running on. Based on the output it can then take the appropriate actions to see what are the commands that can be run on this operating system. Example The following example shows how the parse functions are used to get the details of the operating system on which the program is running. /* Main program */ parse version language level date month year. parse source system invocation filename. language = translate(language) if pos(”REGINA”,language) = 0 then say ”Error , the default interpreter is not Regina” language say ”The Interpreter version/release date is:” date month year say ”The Language level is: ” level say ”The Operating System is” select when system = ”WIN32” then ”ver” when system = ”UNIX” | system = ”LINUX” then ”uname -a” otherwise say ”Unknown System:” system end if rc <> 0 then say ”Error :” rc The output will vary depending on operating system. A sample output is given below. The Interpreter version/release date: 5 Apr 2015 The Language level is: 5.00 The Operating System is Unknown System: WIN64 Bad return code: RC Print Page Previous Next Advertisements ”;
Rexx – Brexx
Rexx – Brexx ”; Previous Next BRexx is a lighter weight implementation of Rexx. It still has a lot of functionality to offer as part of the Rexx implementation. Setting up BRexx The first step in BRexx is to set it up on the local machine. To do this, one needs to perform the following steps − Step 1 − Go to the BRexx download site − https://ftp.gwdg.de/pub/languages/rexx/brexx/html/rx.html Go to the downloads section and download the product. Step 2 − Unzip the contents of the Brexx zipped file. Step 3 − Add the BRexxbin path to the path variable on the system. Step 4 − Create a new variable called RXLIB and point it to the lib folder in the Brexx folder. Running the First BRexx Program Create a file called main.rexx and place the following code in the file. /* Main program */ say ‘hello’ To run the program, run the following command. rexx32 main.rexx When you run the above command, you will get the following output. hello Let us now discuss some of the most commonly used functions available in the BRexx library. Sr.No. Functions available in the BRexx Library 1 acos Command This command is used to get the arc-cosine conversion of a number. 2 cos Command This command is used to get the cosine conversion of a number. 3 sin Command This command is used to get the sine conversion of a number. 4 asin Command This command is used to get the arc-sine conversion of a number. 5 tan Command This command is used to get the tangent conversion of a number. 6 atan Command This command is used to get the arc-tangent conversion of a number. 7 mkdir Command This command is used to create a directory in the current working directory. 8 rmdir Command This command is used to remove a directory in the current working directory. 9 dir Command This command is used to return the entire directory listing. Print Page Previous Next Advertisements ”;
Rexx – Implementations
Rexx – Implementations ”; Previous Next The Rexx language has a lot of various implementations as we have already seen in the previous chapters. Each implementation has its own functionality. Let’s look at the various implementations available for Rexx. OoRexx This is the object oriented version of Rexx. By default, the Rexx basic implementation is all based on procedures. But with ooRexx you can offer greater flexibility by having an Object oriented approach to Rexx. By using ooRexx you can have better re-use through creating re-usable classes and objects. The following program is an example of a simple Rexx program which can be run with the ooRexx implementer. Example /* Main program */ say ‘hello’ To run this program, run the following command. rexx main.rexx When you run the above command, you will get the following output. hello Netrexx This is for all Java based developers as it provides a Java based alternative for the Rexx language. So all of the objects are based on the Java Object Model. The advantage of this framework is that since Java is a widely popular language it becomes easier for developers to use this framework. So in this implementation, the Rexx code is converted to a Java program which can then be run on any Java virtual machine. The following code is an example of a NetRexx program. Create a file called main.nrx and place the following code in the file. /* Main program */ say ‘hello’ To compile the code run the following command − NetRexxC main.nrx You will then get the following output. NetRexxC is the compiler which converts the Rexx program to its java equivalent. java -cp “;;G:NetRexx-3.04GAlibNetRexxF.jar;.” -Dnrx.compiler = ecj org.netrexx.process.NetRexxC main.nrx NetRexx portable processor 3.04 GA build 4-20150630-1657 Copyright (c) RexxLA, 2011,2015. All rights reserved. Parts Copyright (c) IBM Corporation, 1995,2008. Program main.nrx Compilation of ”main.nrx” successful You can now run your java program using the following java command. java main When you run the above command, you will get the following output. Hello Brexx This is a lightweight implementation of Rexx. This is a lighter package than the standard Rexx implementer. But it still has the full functionality of Rexx. The following code is an example of a BRexx program. /* Main program */ say ‘hello’ To run the program, run the following command. rexx32 main.rexx When you run the above command, you will get the following output. hello Print Page Previous Next Advertisements ”;
Rexx – Debugging
Rexx – Debugging ”; Previous Next Debugging is an important feature in any programming language. It helps the developer to diagnose errors, find the root cause and then resolve them accordingly. In Rexx, the trace utility is used for debugging. The trace instruction can be implemented in 2 ways, one is the batch mode and the other is the interactive mode. Let’s look at how to implement both options. Trace in Batch Mode The trace command is used to give a detailed level of each Rexx command which is executed. The general syntax of the trace statement is shown as follows − Syntax trace [setting] Where the setting can be anyone of the following options − A − Traces all the commands. C − Only traces the host commands which are sent to the operating system. E − Only traces the host commands which are sent to the operating system which have resulted in an error. F − Only traces the host commands which are sent to the operating system which have resulted in a failure. I − This provides an intermediate level tracing of Rexx commands. L − This option is if you want to label the tracing as it happens. N − This is the default option in which no tracing happens. Let’s take a look at an example of the trace command. Example Live Demo /* Main program */ trace A /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say ”This is a whole number” return 0 msg : say ” This is an incorrect number ” The output of the above program will be as follows − 5 *-* n = 100.45 if datatype( n, wholenumber ) then signal msg 7 *-* say ”This is a whole number This is a whole number 8 *-* return 0 From the output, you can see that an additional trace was added to the output of the program. The following things can be noted about the output − The line number along with the statement executed is added to the trace output. Each line that gets executed is shown in the trace output. Trace Function Trace can also be enabled with the help of the trace function. The general syntax and example are shown below. Syntax trace() The above function returns the current trace level. Parameters None Return Value The above function gives the current trace level. Example Live Demo /* Main program */ say trace() /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say ”This is a whole number” return 0 msg : say ”This is an incorrect number ” The output of the above program will be as follows. N This is an incorrect number The first line of N denotes that the trace is set to Normal. Setting Trace Value The trace level can be set with the trace function. The general syntax and example are shown below. Syntax trace(travel_level) Parameters trace_level − This is similar to the options available for setting the trace level. Return Value The above function gives the current trace level. Example /* Main program */ say trace() current_trace = trace(”A”) say current_trace /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say ”This is a whole number” return 0 msg : say ” This is an incorrect number ” The output of the above program will be as follows − N 4 *-* say current_trace N 6 *-* n = 100.45 7 *-* if datatype( n, wholenumber ) then 8 *-* signal msg 12 *-* say ”This is an incorrect number” ”This is an incorrect number” Interactive Tracing Interactive tracing is wherein, tracing is carried out as the program runs. Just like in an IDE such as Visual Studio for .Net, in which you can add breakpoints and see how each statement executes, similarly here also you can see the program as each code line runs. The general syntax is as follows − Syntax trace ?options Where, options are the same for the trace command as shown below. A − Traces all the commands C − Only traces the host commands which are sent to the operating system. E − Only traces the host commands which are sent to the operating system which have resulted in an error. F − Only traces the host commands which are sent to the operating system which have resulted in a failure. I − This provides an intermediate level tracing of Rexx commands. L − This option is if you want to label the tracing as it happens. N − This is the default option in which no tracing happens. Let’s take a look at an example of implementing active tracing. Example Live Demo /* Main program */ trace ?A /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say ”This is a whole number” return 0 msg : say ”This is an incorrect number” The output of the above program will be as shown in the following program. The trace will stop at each line of code; then you need to press the Enter button to move onto the next line of code. This is an incorrect number +++ “LINUX COMMAND /home/cg/root/5798511/main.rex” 5 *-* n = 100.45 if datatype( n, wholenumber ) then +++ Interactive trace. “Trace Off” to end debug, ENTER to Continue. +++ 6 *-* signal msg 10 *-* msg : 10 *-* say ”This is an incorrect number” Print Page Previous Next Advertisements ”;
Rexx – Object Oriented
Rexx – Object Oriented ”; Previous Next When you install ooRexx as per the environment chapter, you will also have the ability to work with classes and objects. Please note that all of the following code needs to be run in the ooRexx interpreter. The normal Rexx interpreter will not be able to run this object oriented code. Class and Method Declarations A class is defined with the following Syntax declaration. Syntax ::class classname where classname is the name given to the class. A method in a class is defined with the following Syntax declaration. Syntax ::method methodname Where methodname is the name given to the method. A property in a class is defined with the below Syntax declaration. Syntax ::attribute propertyname Where propertyname is the name given to the property. Example The following is an example of a class in Rexx. ::class student ::attribute StudentID ::attribute StudentName The following points need to be noted about the above program. The name of the class is student. The class has 2 properties, StudentID and StudentName. Getter and Setter Methods The Getter and Setter methods are used to automatically set and get the values of the properties. In Rexx, when you declare a property with the attribute keyword, the getter and setter methods are already put in place. Example ::class student ::attribute StudentID ::attribute StudentName In the above example, there would be Getter and Setter methods for StudentId and StudentName. An example of how they can be used is shown in the following program. Live Demo /* Main program */ value = .student~new value~StudentID = 1 value~StudentName = ”Joe” say value~StudentID say value~StudentName exit 0 ::class student ::attribute StudentID ::attribute StudentName The output of the above program will be as shown below. 1 Joe Instance Methods Objects can be created from the class via the ~new operator. A method from the class can be called in the following way. Object~methodname Where methodname is the method which needs to be invoked from the class. Example The following example shows how an object can be created from a class and the respective method invoked. Live Demo /* Main program */ value = .student~new value~StudentID = 1 value~StudentName = ”Joe” value~Marks1 = 10 value~Marks2 = 20 value~Marks3 = 30 total = value~Total(value~Marks1,value~Marks2,value~Marks3) say total exit 0 ::class student ::attribute StudentID ::attribute StudentName ::attribute Marks1 ::attribute Marks2 ::attribute Marks3 ::method ”Total” use arg a,b,c return (ABS(a) + ABS(b) + ABS(c)) The output of the above program will be as shown below. 60 Creating Multiple Objects One can also create multiple objects of a class. The following example will show how this can be achieved. In here we are creating 3 objects (st, st1 and st2) and calling their instance members and instance methods accordingly. Let’s take a look at an example of how multiple objects can be created. Example Live Demo /* Main program */ st = .student~new st~StudentID = 1 st~StudentName = ”Joe” st~Marks1 = 10 st~Marks2 = 20 st~Marks3 = 30 total = st~Total(st~Marks1,st~Marks2,st~Marks3) say total st1 = .student~new st1~StudentID = 2 st1~StudentName = ”John” st1~Marks1 = 10 st1~Marks2 = 20 st1~Marks3 = 40 total = st1~Total(st1~Marks1,st1~Marks2,st1~Marks3) say total st2 = .student~new st2~StudentID = 3 st2~StudentName = ”Mark” st2~Marks1 = 10 st2~Marks2 = 20 st2~Marks3 = 30 total = st2~Total(st2~Marks1,st2~Marks2,st2~Marks3) say total exit 0 ::class student ::attribute StudentID ::attribute StudentName ::attribute Marks1 ::attribute Marks2 ::attribute Marks3 ::method ”Total” use arg a,b,c return (ABS(a) + ABS(b) + ABS(c)) The output of the above program will be as shown below. 60 70 60 Inheritance Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another. With the use of inheritance, the information is made manageable in a hierarchical order. The class which inherits the properties of other is known as subclass (derived class, child class) and the class whose properties are inherited is known as superclass (base class, parent class). Let’s see an example of inheritance in Rexx. In the following example we are creating a class called Person. From there we use the subclass keyword to create the Student class as a sub-class of Person. Example Live Demo /* Main program */ st = .student~new st~StudentID = 1 st~StudentName = ”Joe” st~Marks1 = 10 st~Marks2 = 20 st~Marks3 = 30 say st~Total(st~Marks1,st~Marks2,st~Marks3) exit 0 ::class Person ::class student subclass Person ::attribute StudentID ::attribute StudentName ::attribute Marks1 ::attribute Marks2 ::attribute Marks3 ::method ”Total” use arg a,b,c return (ABS(a) + ABS(b) + ABS(c)) The output of the above program will be as shown below. 60 Print Page Previous Next Advertisements ”;
Rexx – Error Handling
Rexx – Error Handling ”; Previous Next Rexx has the ability to also work on Error handling as in other programming languages. The following are some of the various error conditions that are seen in Rexx. ERROR − This even is raised whenever a command which is sent to the operating system results in an error. FAILURE − This even is raised whenever a command which is sent to the operating system results in a failure. HALT − This is normally raised whenever an operation is dependent on another operation. An example is if an I/O operation is being halted for any reason. NOVALUE − This event is raised when a value has not been assigned to a variable. NOTREADY − This is raised by any I/O device which is not ready to accept any operation. SYNTAX − This event is raised if there is any syntax error in the code. LOSTDIGITS − This event is raised when an arithmetic operation results in a loss of digits during the operation. Trapping Errors Errors are trapped with the help of the signal command. Let’s take a look at the syntax and an example of this. Syntax signal on [Errorcondition] Where, Errorcondition − This is the error condition which is given above. Example Let’s take a look at an example on this. /* Main program */ signal on error signal on failure signal on syntax signal on novalue beep(1) signal off error signal off failure signal off syntax signal off novalue exit 0 error: failure: syntax: novalue: say ”An error has occured” In the above example, we first turn the error signals on. We then add a statement which will result in an error. We then have the error trap label to display a custom error message. The output of the above program will be as shown below. An error has occurred. An example of error codes is shown in the following program. /* Main program */ signal on error signal on failure signal on syntax signal on novalue beep(1) exit 0 error: failure: syntax: novalue: say ”An error has occured” say rc say signal The output of the above program will be as shown below. An error has occured 40 6 Print Page Previous Next Advertisements ”;