Connection and Program Events in TTWin 4.8

A useful TTWin feature is the ability to define actions, through macros and scripts, that are triggered when a particular TTWin program or connection event occurs.

Earlier versions of TTWin supported a Start Up event, triggered when TTWin was launched, and a Connect event, triggered when a connection was established to a host system.

Recently released TTWin 4.8 adds two new events types, a Disconnect event which fires when a host connection is ended and a Shutdown event which occurs when a user attempts to exit the TTWin program or close a session tab. Read on for more details and examples.

Here the Disconnect string (macro) is configured to launch a TTWin VBA Script

The Disconnect string (macro) is configured to launch a script.

All the event types described here are located under the Configure > General > Session Preferences menu option and are designed to work with TTWin's macro language. When configuring each item, you'll see an Assist... button next to the text field which will launch TTWin's Macro Assistant. The Macro Assistant greatly simplifies the task of creating Macros in TTWin.

Macros or Scripts?

TTWin's Macro language is robust enough to handle a wide range of requirements for interaction and automating behavior, however there may be occasions when you need the kind of power that only a full blown scripting language can provide. In such a scenario you can make use of TTWin's VBA style scripting language which comes complete with an integrated development environment and debugger to enable you to create sophisticated scripts for use in TTWin.

To execute a script in one of the events described here simply use the .Script function of TTWin's macro language. This function allows you to execute a TTWin script. You can enter the macro directly, as shown in the screenshot below or use click the Assist... button to launch the Marco Assistant. The .Script command can be found under the Functions list.

Disconnect String

The Disconnect string (macro) runs when the user clicks the Disconnect button on the program toolbar. One useful application of this event is in enforcing a clean logout from a host system, typically by sending a command to the host system rather than simply dropping the connection from TTWin.

Shutdown String

The Shutdown string (macro) will run when the user tries to close TTWin or a session tab. Much like the Disconnect String, this can be useful in forcing a graceful disconnect from a host system. In fact you may wish to call the same script or macro as in the Disconnect String.

The following VBA style script (TTWin 4.8+) demonstrates how you might use the Shutdown or Disconnect macros to cleanly end a host session. If it determines that the session is currently connected to a host system it sends the text 'logout' followed by a carriage return character, pauses for 500 milliseconds, and then checks the connection state again to ensure that a clean logout has been performed.

Option Explicit
Sub Main
	Dim a As Long
	If TTWin.IsConnected Then
		TTWin.KbdText "logout" + Chr(10)
		a = 0

		'Wait for up to 500ms for the host to disconnect
		While TTWin.IsConnected And a < 5
			Wait 0.1
			a = a + 1
		Wend
		If TTWin.IsConnected Then
			MsgBox "Logout Failed, Session cannot be closed"
		End If
		'To force a disconnect uncomment the next line
		'TTWin.CommDisconnect
	End If
	'To force a close session uncomment the next line
	'TTWin.Close
End Sub
Connect String

The Connect String event triggers when TTWin establishes a connection to a remote host. This event can be useful in sending initial interaction to a host, for example, automating a login.

Start Up String

The Start Up String will run when the TTWin program is launched. Some example uses of this macro are to display a welcome message or show a custom list of predefined host sessions that the user may wish to launch.

For more in depth information on macros or scripting in TTWin, refer to the TTWin 4 User Manual included in your TTWin installation or, alternately, downloadable from the support downloads area of ttwin.com.
|