Script for Exchanging Data with Microsoft Excel
This script opens Microsoft Excel to a new workbook. It also opens TinyTERM Plus with a preconfigured connection and logs in. It then populates the workbook with data, some drawn from TinyTERM, some directly from the script. Finally, it uses data in a workbook cell to terminate the TinyTERM connection.
Script Command | Description | |
---|---|---|
Set objExcel = CreateObject("Excel.Application") |
Associates the name objExcel with Microsoft Excel for Windows and starts an instance of it. | |
objExcel.Visible = True |
Displays the Excel window. Note that this uses different syntax than that required for TinyTERM Plus. | |
Set objWorkbook = objExcel.Workbooks.Add |
Associates objWorkbook with a new Excel workbook. | |
Set objWorksheet = objWorkbook.Worksheets(1) |
Associates objWorksheet with Sheet 1 of objWorkbook. | |
Set tt = WScript.CreateObject("Century.TinyTERM") |
Associates the name tt with the Century.TinyTERM program and starts an instance of it. | |
tt.Show() |
Displays the TinyTERM Plus window. | |
Set objte = tt.Control |
Associates the name objte with the ActiveX control currently loaded in TinyTERM. | |
objte.Connect() |
Calls the Connect() method of objte, which connects to the host. | |
Call objte.WaitForConnect(1000) |
Waits up to 1000 seconds for a successful connection. | |
objte.WaitForString(0,15,31,"Username") |
Calls the WaitForString method to read text from row 15, column 31 of the TinyTERM emulator window. | |
objte.Xmit "username<^I>password<^M> |
Sends the word username followed by a tab (^I), then the password, and finally a carriage return (^M) to login to the host. | |
WScript.Sleep(2000) |
Pauses the script for 2000 milliseconds, or two seconds, to allow login to complete. | |
s = objte.GetSelection(60, 5, 12, 1, 0) |
Sets variable s to the text that starts in column 60, row 5. It extracts data 12 characters long and 1 row high as plain text. | |
objWorksheet.Cells(1, 1) = s |
Enters the data from s into row 1, column 1 of the worksheet (cell A1). | |
s = objte.GetSelection(73,2, 8, 1, 0) |
Gets 8 characters starting at column 73, row 2 and stores them in variable s. On a standard 24x80 screen, this would be the last eight characters of the row. | |
objWorksheet.Cells(1, 2) = s |
Enters the data from s into row 1, column 2 of the worksheet. | |
s = objte.GetSelection(73,3, 8, 1, 0) |
Gets 8 characters starting at column 73, row 3 and stores them in variable s. | |
objWorksheet.Cells(1, 3) = s |
Enters the data from s into row 1, column 3 of the worksheet. | |
objWorksheet.Cells(1, 4) = "logoff" |
Enters the word logoff into row 1, column 4 of the worksheet. | |
r = objWorksheet.Cells(1, 4).Text |
Reads the text from row 1, column 4 into the variable r. | |
objte.xmit r & <^M>" |
Sends the contents of r followed by a carriage return to the mainframe. | |
Call objte.WaitForDisconnect(0) |
Waits for the host connection to end. | |
tt.Quit |
Closes TinyTERM completely. |
This is not the most efficient way to script some of this interaction. The extra steps, particularly the use of variable r, are intended for illustration, not as best practices.