Reflection Desktop VBA Guide
HowTos / Close Open Systems Sessions Gracefully
In This Topic
    Close Open Systems Sessions Gracefully
    In This Topic

    You can prevent users from closing sessions until certain conditions are met.

    If you prefer to run macros in pre-configured sessions instead of creating your own sessions, you can download the VBA Sample Sessions and open the close-sessions-gracefully.rdox (Open Systems) file. The download package contains everything you need to run the macros in this file. See Download the VBA Sample Sessions.

     

    This sample requires users to close an application before they terminate the session. 

    This sample applies only to Open Systems terminals.

    To run this sample

    1. Create a new VT terminal session and enter "demo:UNIX" in the Host name / IP Address field.
    2. In the Visual Basic Editor Project window, copy the code into the View object module.
                     
      Close session gracefully
      Copy Code
      'This sample allows closing of a session only after applications are closed and other conditions are met
      Private Function View_Closing(ByVal sender As Variant) As Boolean
          Dim screenAtLogoff As String
        
          'Get all the displayed text before the view closes
          screenAtLogoff = ThisScreen.GetText2(1, 1, ThisScreen.DisplayRows, ThisScreen.DisplayColumns)
       
          'Find out if the displayed text has the phrase that indicates the application is properly closed
          If InStr(1, screenAtLogoff, "connection has terminated") = 0 Then
              'If exit is not found do not allow closing
              MsgBox "You can't close this session until you close the application"
              View_Closing = False
          Else
              View_Closing = True
          End If
       
      End Function
      
                                                   
      
    3. On the first screen, enter any credentials to log in.
    4. Try to close the session. (This opens the message box that indicates you need to close the application.)
    5. On the command prompt, enter "exit" to close the demo application and then close the session. 

    Concepts

    This macro handles the Closing event to check for a user exit command. If it finds the command in the display memory,  the event is set to true and the application closes. If not, the event is cancelled, and the user is not allowed to close the session. 

     

    See Also