Execute ReXX in any .Net Visual Studio product
If you want to produce an application with variable features, or
want to deliver an application to an end-user, where certain
procedures are yet to be defined in detail, consider this package.
On defined points in your application, you call a ReXX-program
with the possibility for ReXX to use callback functions of your
application, with full access to the ReXX environment.
You
deliver the backbone system and implement (or have the end-user do
it) procedures to perform the implementation-specific needs. Take a
look at the ARCATSY
archives cataloguing system for instance.
Download.
You may download the
sample: ReXX v 1.0.0.1 (nov, 2012) and
use it and distribute is as you like. It's including the RxLib.Dll
containing the runtime modules.
Make sure you have Microsoft
DotNet runtime 3.5 or higher installed if you're still running
Windows XP. Search in Microsoft.com for the "NET Framework (x86)
redistributable package" and install it first.
The sample is
written in Visual Basic 2010 for DotNet 3.5, and contains the minimum
code to run a ReXX program. Of course your application may be written
in any language, that supports .Net dll's.
To successfully implement the RxLib you need to follow this scheme.
First you need to know whether you are going to call a Rexx script one at a time, or whether your application starts a Rexx script while another Rexx script is still running.
An example: The application calls a script. The script finds a command and invokes the application through the command-event. In the command-event your application may or may never start another Rexx script.
In the first case the call structure is Appl → Rexx → Appl cmd → return to Rexx → on exit of Rexx: return to Appl: no nested Rexx scripts
In the latter: Appl → Rexx1 → Appl cmd → Rexx2 → Appl cmd → return to Rexx2 → on exit of Rexx2: return to Appl cmd → return to Rexx1 → on exit of Rexx1: return to Appl: Rexx2 is nested in Rexx1. As the application needs to be able to access both Rexx environments, it's the applications task to declare them and keeps them alive as long as they are needed.
Or: The application calls a script. The script finds a call or function in Rexx and invokes the other Rexx script.
And now: Appl → Rexx1 → Rexx2 → on exit of Rexx2: return to Rexx1 → on exit of Rexx1: return to Appl. Rexx2 is again nested in Rexx1. As the application still needs to be able to access both Rexx environments, it's the applications task to declare them and keeps them alive.
To implement the first (or only) Rexx environment, in which you may run as many scripts one after the other, you declare a “Dim WithEvents Rx As New RxLib.Rexx(New RxLib.RexxStor)” where “Rx” is the variable that names the Rexx class. To implement a subsequent Rexx environment, while executing a command of a previous Rexx, it would have been so nice if VB had only allowed to specify a “Dim WithEvents Rx2 As New RxLib.Rexx(New RxLib.RexxStor)” inside the Sub that handles the command. But alas Dim with events is only allowed in a class, not in a sub. Thus you'll have to declare a new class implementing subsequent Rexx scripts, and from this secondary class invoke the event-handlers of the primary. With this structure you may nest Rexx scripts at any level, your application maintains one primary and as many secondary environments, as there are active scripts. Below I'll give the recipe to workt it out.
Launch the SampleForm in debug and run it, Choose the various samples and see how they pass through the code of the application. Then paste the pieces you need in your application.
Description of the various elements.
Declaring the Rexx environment.
Dim WithEvents Rx As New RxLib.Rexx(New RxLib.RexxStor)
in the application class before the sub's. The Rexx environment is created and initialized and is ready for use. The name Rx is at your choice, but I use it in the syntax examples below as I did in the Sample Program.
Public members of RxLib:
|
1 |
Comp Compile the Rexx program Public Function Comp(ByVal Filename As String) As Integer Syntax for use: Dim DrRc As Integer DrRc = Rx.Comp(Filename) If DrRc = 0 Then ' compilation successful End If Filename is filename of the script |
||||||||
|
2 |
Exe Execute the Rexx program Public Function Exe(ByVal param As String) As Integer Syntax for use: Dim DrRc As Integer DrRc = Rx.Exe(param) param is the string containing the parameter. |
||||||||
|
3 |
CancRexx Public Shared CancRexx As Boolean if set to True, halts the Rexx program that is executing. |
||||||||
|
4 |
DoSay Event dosay(ByVal sayStr As String) executed when the Rexx script processes a Say Syntax for handler: Friend Sub RexxSay(ByVal sayStr As String) Handles Rx.dosay The string sayStr,result of the say, is to be passed to the user.
Closely connected to DoSay: DoPull Event doPull(ByRef PullStr As String) executed when the Rexx script processes a (Parse) Pull Syntax for handler: Friend Sub RexxPull(ByRef PullStr As String) Handles Rx.doPull The string PullStr must have assigned the pulled value, which is to be passed to Rexx. |
||||||||
|
5 |
RexxHandlesSay Public Shared RexxHandlesSay As Boolean = True Set to True before executing the script, if you don't write a say or a pull event handler, and you leave the presentation to Rexx. Otherwise set to False. Rexx shows the result of SAY in a messagebox and/or an inputBox, and allows the user to cancel the script. You may act on the cancellation handling the DoCancel event |
||||||||
|
6 |
DoCancel event. Syntax for handler: Friend Sub RexxCancel() Handles Rx.doCancel executed when, in the builtin SAY messagebox, the user decides to cancel the script. You cannot undo the cancellation. |
||||||||
|
7 |
DoCmd event. Syntax for handler: Friend Sub RexxCmd(ByVal ExecLayer As String, ByVal RexxCommand As String, ByVal e As RxLib.RexxEvent, ByRef RexxEnv As RxLib.Rexx) Handles Rx.doCmd executed when the Rexx script passes a command to the application. Parameters passed to the application: _ ExecLayer contains the (implicit) Address string, allowing for commands to go to various environments. An example in old mainframe terminology: in the editor a script may address a command to the editor (XEDIT) or to the operating system (CMS) in which the editor runs. The application defines which strings are valid. There are no limitations to number and length. _ RexxCommand contains the string that Rexx contructed for the command, substituting the variables on the commandline _ e contains the returncode for the event, to be set by the application before returning control to Rexx. In the script it may be tested using the builtin variable rc. _ ByRef RexxEnv is the Rexx environment in which the current script is running. You'll need it, if you want to communicate with Rexx by means of the exposed members, eg. GetVar, SetVar, Qstack |
||||||||
|
|
Inside the body if the event handler you have access to the Rexx environment by means of the exposed members: |
||||||||
|
|||||||||
|
8 |
DoNewRexx event. Needed only if you want to nest Rexx scripts. Syntax for handler: Event doNewRexx(ByVal env As String, ByVal cmd As String, ByVal prm As String, ByVal e As RexxEvent, ByRef RexxEnv As Rexx) Executed when Rexx wants to initiate a subroutine written in Rexx. As the application surely wants to intercept the events for the subroutine, you'll have to declare the Rexx evironment and set up handlers for it. The source for all this is practically fixed. You may alter the names but not the function. Omit those events that your application does not want to handle. The structure consists of the Sub RexxNewRexx in the main class and of the complete Public Class DoRexx where you substitute the name of the Main form with your main formname. The DoRexx Class is needed likewise when you want to execute a Rexx script from within the DoCmd handler. The reason for this rigid structure lies in the fact that the Rexx program in the Dll (or your application in the doCmd handler) cannot declare a New Rexx With Events, which makes it your application's task to do it using a separate class. Visual Basic leaves no other choice to the programmer. |
||||||||
|
9 |
DoStep event. Syntax for handler: Friend Sub RexxStep() Handles Rx.doStep executed when the Rexx interpreter has executed another 30000 steps in the pseudocode. To intercept unexpected loops. |
Number of Visitors for this page:
Visiting the sponsor is your choice.........
'); //-->