• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Tachytelic.net

  • Sco Openserver
    • Sco Unix Support
    • SCO Openserver Installation ISOs
    • SCO Openserver Binaries
    • Add a Hard Drive to an Openserver 5 Virtual Machine
    • Install SCO Vision SQL-Retriever ODBC Driver on Windows 10
    • License Expired on Virtual SCO Openserver Installation
    • How to reset the root password on SCO Openserver 5
  • Scripting
    • PowerShell
      • Add leading zeros
      • Check if a File Exists
      • Grep with Powershell
      • Create Environment Variables
      • Test for open Ports
      • Append to a Text File
    • VBScript
      • Check if a File Exists
      • lpad and rpad functions
      • Windows Update E-Mail Notification
  • Office 365
    • Connect to Office 365 with PowerShell
    • Add or remove an email alias using Powershell
    • Change Primary email address of Active Directory user
    • How to hide an AD user from the Global Address List
    • How to hide mail contacts from the Global Address List
    • Change the primary email address for an account with PowerShell
    • Change Primary email address of an AD User
    • Grant a single user access to access to all calendars
    • Forward email to an external address using Powershell
    • Convert shared mailbox to user mailbox with Powershell
  • Get in Touch
  • About Me
    • Privacy Policy

Emailing from Turbosoft TTwin 4 Terminal Emulator with VBA Script

November 12, 2019 by Paulie Leave a Comment

I’ve got a lot of customers with legacy systems, by chance most of them use Century TinyTerm. One, who uses TTwin 4 by Turbosoft asked if it would be possible to initiate an email from the contents of the emulation screen. Take this screen for example:

Image of typical text based legacy system using TTWin 4 to connect.

I investigated and thought it should be possible. TTwin uses VBA engine provided by WinWrap . It is easy to capture the contents of a fixed portion of the screen, but the email address could be anywhere in the display. A slight complication.

So I write a script which could be activated by a mouse shortcut (which is quite a neat feature of this emulator). The script scans the screen for email addresses and then initiates the default mail client on the PC to send an email. Here is the code:

Option Explicit

Sub Main
	Dim screenContents() As String, emailAddress As String
	ScreenContents = getScreenContents(24, 80)
	emailAddress = findEmailOnScreen()
	If emailAddress <> "notFound" Then
		Shell ("rundll32.exe url.dll,FileProtocolHandler mailto:" & emailAddress, 1)
	End If
End Sub

'Function to search for an email address on screen
Function findEmailOnScreen() As String
	Dim ScreenContents() As String, Screenline() As String
	Dim regExp As New RegExp, i As Integer, j As Integer
	ScreenContents = getScreenContents(24,80)

	With regExp
		.Global = True
		.Multiline = True
		.IgnoreCase = True
		.Pattern = "((?:[A-Z0-9_%+-]+\.?)+)@((?:[A-Z0-9-]+\.)+[A-Z]{2,4})$"
	End With

	For i = 0 To UBound(ScreenContents)
		Screenline() = Split(ScreenContents(i), " ")
		For j = 0 To UBound(Screenline)
			If(regExp.Test(Screenline(j))) Then
				findEmailOnScreen=Screenline(j)
				Exit Function
			End If
		Next		
	Next

	findEmailOnScreen = "notFound"
End Function

'Function to get the entire contents of the screen as an array
Function getScreenContents(Height As Integer, width As Integer)
	Dim screenLines() As String
	ReDim screenLines(Height)
	Dim lineText As String, count As Integer

	Do
		TTWin.DispReadText  count,0,lineText,width
		screenLines(count) = lineText
    	count=count+1
	Loop Until count = Height
	getScreenContents=screenLines()
End Function

It works like this:

  • Loads each line of the display into an array
  • Splits each line of the array by the space character into another array.
  • Uses regex to see if any element of the array looks like an email address
  • Opens the default mail client if a match is found using rundll32.exe

The script could be improved but it works well and it is a decent start.

Image showing Email being initiated from a VBA Script within Powersoft TTWin 4
Mouse Shortcut of Right-Click Shift initiates the script and a new email is created.

TinyTerm has the same scripting engine as TTWin 4, I tried and failed to create the same function with TinyTerm. I am sure it is possible, but the programmers documentation wasn’t clear to me.

This is the first time I have used TTWin, it seems like a really good product, things I like about it:

  • Multiple sessions support is good with thumbnails in a dedicated panel.
  • Scripting engine is easy to get to grips with.
  • Hot spots, keyboard and mouse events are easy to setup to provide quick automation.
  • The macro recorder is easy to use and works well.

The programmers documentation could be better, more example code would help a lot.

Do you have a text based legacy system? If so I offer lots of ways to enhance and modernise, just get in touch to discuss your requirements.

Related

Filed Under: Scripts & Utilities Tagged With: Legacy, VBA

Reader Interactions

Leave a Reply Cancel reply

Primary Sidebar

Link to my LinkedIn Profile
Go to mobile version