Link to home
Start Free TrialLog in
Avatar of PETAdmin
PETAdminFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Lotus Script Libraries error messages

I have a lotus script program that uses an dll file, this is referenced with the command
Uselsx "*RFC"

This works fine, but if the users are either missing in the registry entry or dll file, then they get a generic message. Is it possible to find a way to create a new error message explaining to the user how go solve this issues. Or is their a way to check for this file.
ASKER CERTIFIED SOLUTION
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PETAdmin

ASKER

I don't believe that the library does load when the file is missing. The exact error message is Error Loading USE or USELSX module: *RFC.

But I certainly like your solution for checking for the file, since it should be located in the same place for all users, something perhaps I can run on database open.

But it would be nice if their was a way to error trap the message, and to give to the user a more useful error message, that tell them how to solve this issue. But since the USE command is based in the options section I guess this might not be possible?
Sorry, it's not possible to detect when a library won't load, but there may be a work-around.

You could split your operation into two stages.  One stage checks for the existance of the required components and the other does the work if the first stage passes successfully.

Here's one way to accomplish this.

1.  Create 2 agents.
2.  In one agent, check for the existance of the file and write the status to an environment variable.
3.  In the other agent, do your operation.
4.  Assuming that you're using an action button to start the operation, you can use an @Formula like this:

@Command([RunAgent]; "CheckRequirements");
bProceed := @If(@Environment("REQUIREMENT_STATUS") != "PROCEED"; @False; @True);
@Environment("REQUIREMENT_STATUS"; "");
@If(bProceed; @True; @Return(0));
@Command([RunAgent]; "YourAgent");
Another thought:  If your code is in a class, you might be able to use a dynamically loaded class.

This is a bit advanced and causes your code to be late-bound which can be a bit slower, but might solve your problem in a more elegant manner.

I use classes for just about everything complicated.  Here's how I instantiate a class in one LotusScript library from another one without using a Use statement in the Options event:

1.  Declare a global variable (Declarations) in the same library that contains the LoadClass function below.

Public objFactoryClass As Variant ' Temporary storage for dynamically-loaded classes.

2.  Here's the function I use to load a class at run time:

Public Function LoadClass(Byval className As String, Byval libraryName As String) As Variant
      
      '/**
      ' * Dynamically loads a class.
      ' * <p></p>
      ' * Use this function to get a class instance when the class you
      ' * need is not defined in the current library.<b>
      ' * Note: The class's constructor cannot accept any parameters.
      ' * @param className The name of the class to load.
      ' * @param libraryName The name of the library where the class is defined.
      ' * @return A new instance of the specified class.
      ' */
      
      Dim code As String
      code = |Use "| & libraryName & |"
              Set objFactoryClass = New | & className
      Execute code
      Set LoadClass = objFactoryClass
      objFactoryClass = V_EMPTY
      
End Function

3.  I have not tested this, but you might be able to trap the error (On Error ... Goto) when the library is loaded on the "Execute" line.

Come to think of it, you could use this technique in conjunction with the first workaround instead of testing for the actual file. In agent 1, you could try this:

Sub Initialize
      
      On Error Goto CATCH
      Dim sess As New NotesSession()      
      Call sess.SetEnvironmentVar("REQUIREMENT_STATUS", "")
      Execute {Use "YourLibraryName"}
      Call sess.SetEnvironmentVar("REQUIREMENT_STATUS", "PROCEED")
      
      
CATCH:
      
      Call sess.SetEnvironmentVar("REQUIREMENT_STATUS", "STOP")
      Exit Sub
      
End Sub

Again, I have not tested the ability of the LotusScript engine to trap this type of error.  If this works, you will have a function that tests whether a library can be loaded.
Fantastic thanks for you help, I went for the simplist solution in the end, which was just to check for the file, and if it doesn't exists give a suitable error message. When I have some more time I think I will also at the last solution as a possibillty which is certainly a nice way of doing this.