PowerTerm Pro VBA Sample Scripts

PowerTerm Pro provides several sample scripts designed for frequent tasks. The following table lists the sample scripts and their parameters:

Script

Parameters

Parameter Values

APPC

System name

Specify the name of the system.

 

Device name

Specify the name of the device.

BAPI

Host name

Specify the name of the host.

COMM

Port number

1 – 4.

 

Baud rate

300 - 115200.

 

Protocol type

none, xonxoff, hardware.

 

Phone number

 

CTERM

Node name

Specify the name of the CTERM node.

DDE

   

KEYS

   

LAT

Service name

Specify the name of the service.

MSSNA

LU name or LU pool name

Specify the LU name or LU pool name.

NWLAT

user name (a NetWare user name without password)

Specify the user name.

 

Service name

Specify the name of the service.

NWSAA

Server name (a NetWare for SAA server name)

Specify the name of the server.

 

User name (a NetWare user name without password)

Specify the name of the user.

 

Service name (profile)

Specify the name of the service.

 

LU category

Public, pooled, dedicated

 

LU name or LU pool name

Specify LU name or LU pool name.

PRINTER

   

TELNET

Host name

Specify the name of the host.

 

Telnet port number

Specify the telnet port number.

TN3270

Host name

Specify the name of the host.

 

Telnet port number

Specify the telnet port number.

 

LU name

Specify LU name.

TN3270E

Host name

Specify the name of the host.

 

Telnet port number

Specify the telnet port number.

 

LU name

Specify LU name.

TN5250

Host name

Specify the name of the host.

 

Telnet port number

Specify the telnet port number.

All parameters must be typed in lowercase letters.

Programming an Existent Script

An example of a PSL script:

Step 1: From within the Microsoft VBA editor, select Insert|Project).

Step 2: Type in name of the project.

Step 3: Place the cursor in the middle of the Public Sub routine named Telnet.

Step 4: Type the word "session" followed by a period. The IntelliSense help displays all the possible selections.

Step 5: Select CommType. The word CommType appears after the period.

Step 6: Type the word "session" followed by a period. The IntelliSense help displays all the possible selections.

Step 7: Select HostName. The word HostName appears after the period.

Step 8: Type MsgBox ("Good morning")

Step 9: Type the word "session" followed by a period. The IntelliSense help displays all the possible selections.

Step 10: Select TelnetPort. The word TelnetPort appears after the period.

Step 11: Type the word "session" followed by a period. The IntelliSense help displays all the possible selections.

Step 12: Select Open. The word Open appears after the period.

The script for VBA:

Public Sub Telnet()

Session.CommType = pt_Telnet

Session.HostName = "126.0.0.200"

MsgBox ("Good morning")

Session.TelnetPort = ""

Session.Open

End Sub

Saving a Customized VBA Project

You can open the scripting examples file and make changes according to your own specific requirements and use them afterwards.

Running VBA Scripts from the Command Line

On the Command line, position your cursor after the .EXE file name, add a space and then type the name of the required script (.pcf) file.

You can also add parameters to the VBA script file.

On the Command line, position your cursor after the PSL script name, add a space and type the required parameters. Parameters should be separated by a space.

Syntax

<n.exe> <pcf file> <VBA module.macro name> <parameter 1> < parameter 2>…

Example:\PowerTerm Pro\PTW32pro.EXE Telnet.pcf abc

PowerTerm Pro VBA Sample Project

This project demonstrates how you can utilize VBA in conjunction with PowerTerm Pro.

You can view the VBA Sample Project code by proceeding to Tools>Macro>Advanced>Open VBA Project and selecting the file ptvbasmpl.pcf

A description for each example follows:

Name

Description

Home

Allows the users to access the Internet,

e-mail and snail mail.

Scripting Examples

Demonstrates several scripts which interact with PowerTerm Pro.

Internet

Launches the user’s Internet browser to a desired URL or Internet site.

Auto Login

Performs an effortless login to the host. The scheduler can automatically perform this task at any designated time in the future.

Power Terminal

Sends the PowerTerm Pro emulation screen display to various destinations.

System Info

This screen demonstrates how VBA assists you in interacting with the API. It displays a list of all visible windows operating on the system and their relative positions. Double-clicking on any one of the items on the list will open up that program.

FTP

Provides a user-friendly interface to connect to an FTP host.

Multi Session Control

This screen demonstrates how VBA assists you in interacting with multiple screen sessions of PowerTerm Pro. It displays a list of all visible PowerTerm Pro sessions operating on the system and their relative positions, size and title. Selecting any one of the items on the list will display this information. The relative positions, size and title can be modified.

Scripting Examples

The Scripting Examples demonstrates several scripts, which interact with PowerTerm Pro.

This table includes all the scripting examples, their parameters and what they accomplish:

Option

Parameters

Results

Change PowerTerm Pro Size

Increases and decreases the dimensions of the Pro emulation screen.

Change PowerTerm Pro Position and Title

Pro emulation screen who is in constant motion.

Show Capture Files

File name

Opens up the Capture files.

Capture Files and Excel Interaction

Captures the emulation screen and inserts its contents into an Excel spreadsheet.

Tn5250

Host, telport As Variant*,

Opens a TN5250 connection (Via TCP/IP WINSOCK api).

Tn3270e

Host, telport As Variant*, luName As Variant*

Opens a TN3270E connection (Via TCP/IP WINSOCK api).

Tn3270

Host, telport As Variant*, luName As Variant*

Opens a TN3270 connection (Via TCP/IP WINSOCK api).

Telnet

Host, telport As Variant*

Opens a TELNET connection (Via TCP/IP WINSOCK api).

Printer

This script file will read PowerTerm's default printer name. According to the printer name it will select the appropriate printer escapes file.

LAT

Service

Opens a LAT connection (Via Digital's PATHWORKS LAT).

Mssna

LU name

Opens an IBM MainFrame connection (Via Microsoft's SNA gateway).

Ole

Opens Excel.

NwLat

User, Service

Opens a LAT connection (Via Novell's NetWare for LAT).

Nwsaatcp

Server, user, service, luCategory,

Lu Name As Variant*

Opens an IBM MainFrame connection (Via Novell's NetWare for SAA using TCPIP).

Nwsaat

Server, user, service, luCategory,

Lu Name As Variant*

Opens an IBM MainFrame connection (Via Novell's NetWare for SAA).

Cterm

Node name

Opens a CTERM connection (Via Digital's PATHWORKS DECnet).

Comm

Commport Commbaudrate*

ProtocolType*

PhoneAsVariant*

Opens a COM port.

Bapi

host

Opens a BAPI connection (TCP/IP Telnet connection via BAPI api).

Appc

System, device

Opens an AS/400 connection (Via APPC).

RestorePro

Restores Pro emulation window.

PrintScreen

Sends screen data to default printer.

NotePadExe

Opens Notepad.

MaximizePro

Maximizes Pro emulation window.

ReceiveFile

Receives the file from the host.

SendFile

Host, user As String, Password*

Sends the file to the host.

An asterisk indicates that a parameter is optional.

Scripting Examples Code

The scripting examples code was provided with comments in order to facilitate the end-user who chooses to adapt these scripts by making small modifications. You can open the scripting examples file and make these changes according to your own specific requirements and use them afterwards. The code is also provided below for you to examine.

For Internet Explorer 4.0 and above: select ptvbasmpl.pcf

Other versions: select ptvbasmplx.pcf

Public Sub Accordion() 'Accordion effect

Dim step, Ratio, Ratio2, height As Long, width As Long

Dim WindowWidth As Long

Dim WindowHeight As Long

Dim i As Integer i = 1 'Default value, should change according to what the user wants

WindowWidth = GetSystemMetrics(0)

WindowHeight = GetSystemMetrics(1)

width = 300

height = 200

Ratio = WindowWidth / WindowHeight

step = 4 'Default value, should be changed if the user wants something else

Ratio2 = step / Ratio

PtermPro.SetWindowPosition 0, 0

For i = 1 To 1 Step 1

Do While width < WindowWidth

DoEvents

'main.cmdactiion.SetFocus

If mystop Then

PtermPro.SetWindowPosition 0, 0

'main.Show

Exit Sub

End If

PtermPro.SetWindowSize width, height

width = width + step

Loop

Do While width > 300

DoEvents

If mystop Then

PtermPro.SetWindowPosition 0, 0

' main.Show

Exit Sub

End If

width = width - step

PtermPro.SetWindowSize width, height

Loop

Do While height < WindowHeight

DoEvents

If mystop Then

PtermPro.SetWindowPosition 0, 0

' main.Show

Exit Sub

End If

height = height + step

PtermPro.SetWindowSize width, height

Loop

Do While height > 300

DoEvents

If mystop Then

PtermPro.SetWindowPosition 0, 0

' main.Show

Exit Sub

End If

height = height - step

PtermPro.SetWindowSize width, height

Loop

Do While width < WindowWidth

DoEvents

If mystop Then

PtermPro.SetWindowPosition 0, 0

' main.Show

Exit Sub

End If

width = width + step

height = height + step / Ratio

PtermPro.SetWindowSize width, height

Loop

Do While width > 300

DoEvents

If mystop Then

PtermPro.SetWindowPosition 0, 0

' main.Show

Exit Sub

End If

width = width - step

height = height - step / Ratio

PtermPro.SetWindowSize width, height

Loop

Next i

End Sub

Sub Pos() 'Changes the window position

Dim WindowWidth As Long

Dim WindowHeight As Long

Dim Flag As Boolean

Dim s As Integer

Dim n_loops As Integer

Dim stam As Integer

Dim wonderful_1 As String

Dim Title As String

s = 0

Flag = True

WindowWidth = GetSystemMetrics(0) - 50

WindowHeight = GetSystemMetrics(1) - 50

Dim X As Single

Dim Y As Single

Dim i As Integer

i = 0

X = 0

Y = 0

PtermPro.SetWindowPosition 0, 0

wonderful_1 = "PowerTerm is wonderful! "

Title = wonderful_1 + wonderful_1 + wonderful_1 + wonderful_1 + wonderful_1

For i = 0 To 1000 Step 1

DoEvents

'main.cmdactiion.SetFocus

If mystop Then

PtermPro.SetWindowPosition 0, 0

PtermPro.SetWindowTitle "PowerTerm Pro"

PtermPro.SetWindowSize 600, 450

'main.Show

Exit Sub

End If

If Flag Then

Select Case s

Case 0

X = X + Math.Rnd * 8

Y = Y + Math.Rnd * 8

Case 1

X = X + Math.Rnd * 8

Case 2

Y = Y + Math.Rnd * 8

End Select

Else

Select Case s

Case 0

X = X - Math.Rnd * 8

Y = Y - Math.Rnd * 8

Case 1

X = X - Math.Rnd * 8

Case 2

Y = Y - Math.Rnd * 8

End Select

End If

If X > WindowWidth Or Y > WindowHeight Then

Flag = False

End If

If X < 0 Or Y < 0 Then

Flag = True

If s = 0 Then

s = 1

Y = 0

X = 0

ElseIf s = 1 Then

s = 2

Y = 0

X = 0

ElseIf s = 2 Then

s = 0

Y = 0

X = 0

End If

End If

PtermPro.SetWindowPosition X, Y

n_loops = VBA.Len(Title) * 2

'While n_loops > 0

' If mystop Then

' PtermPro.SetWindowPosition 0, 0

' main.Show

' Exit Sub

'End If

Call SetWindowTitle(Title)

Title = Mid(Title, 2) + VBA.Left(Title, 1)

Sleep (0.05)

'stam = 50000

'While stam > 0

'stam = stam - 1

'Wend

'n_loops = n_loops - 1

'Wend

Next i

End Sub

Sub capture files

main.commondialog.CancelError = True

main.commondialog.Filter = "All Capture Files (*.Log_*) |*.log_VT;*.log_5250|VT Capture Files (*.log_VT) |*.log_VT|IBM 5250 Capture Files (*.log_5250) |*.log_5250|"

main.commondialog.InitDir = globalpath & "\Vba\CaptureFiles"

main.commondialog.FileName = ""

main.commondialog.Flags = &H4

main.commondialog.ShowOpen

If Err = 32755 Then Err.Clear

myfile = main.commondialog.FileName

If myfile = "" Then

Exit Sub

Else

temppos = main.Top

main.Top = GetSystemMetrics(1) - 250

index = VBA.InStr(myfile, "log_")

If index <> 0 Then

If Mid(myfile, index + 4, 2) = "VT" Then

PtermPro.Setup.EmulationType = ptVt320_7

tmp = Mid(myfile, 1, index + 5)

PtermPro.InputTrace tmp

myfile = Mid(myfile, index + 7, VBA.Len(myfile) - index + 7)

Else

PtermPro.Setup.EmulationType = pt5250_Display

tmp = Mid(myfile, 1, index + 8)

PtermPro.InputTrace myfile

myfile = Mid(myfile, index + 7, VBA.Len(myfile) - index + 1)

End If

End If

End If

Sub capture files and excel interaction

If VBA.Len(VBA.Dir(globalpath & "\Vba\CaptureFiles\capture_STT.log_VT")) = 0 Then

MsgBox "Unable to find capture file", vbCritical, "Error"

Exit Sub

End If

myapplication.setup.EmulationType = 4

myapplication.InputTrace globalpath & "\Vba\CaptureFiles\capture_STT.log_VT"

checkembed = True

If myapplication.ExcelEmbedded Then

If Not ObjectInitialize(EXCELAPPLICATION) Then Exit Sub

Else

If Not ObjectInitialize(EXCELAPPLICATION, True) Then Exit Sub

End If

exportscreentoexcel

checkembed = False

Set GlobalExcel = Nothing

Public Function ObjectInitialize(AppToInit As Integer, Optional isnew As Boolean = False) As Boolean

Dim myerror As String

Dim isembed As Boolean

'On Error Resume Next

'create new instance of office application or get current running instance

On Error GoTo errorhandler

ObjectInitialize = True

If checkembed Then

Select Case AppToInit

Case 1

If myapplication.WordEmbedded Then isembed = True

Case 5

If myapplication.ExcelEmbedded Then isembed = True

End Select

End If

On Error Resume Next

If AppToInit <> 4 And isembed And AppToInit <> 2 And AppToInit <> 3 Then

Select Case AppToInit

Case 1

myapplication.ExecEmbedded 0

Set GlobalWord = GetObject(, "Word.Application")

Case 5

myapplication.ExecEmbedded 1

Set GlobalExcel = GetObject(, "excel.application")

End Select

Else

If Not isnew Then

Select Case AppToInit

Case 1

Set GlobalWord = GetObject(, "Word.Application")

Case 2

Set GlobalPower = GetObject(, "Powerpoint.application")

Case 3

Set GlobalOutlook = GetObject(, "outlook.application")

Case 4

Set GlobalInternet = GetObject(, "InternetExplorer.Application")

Case 5

Set GlobalExcel = GetObject(, "excel.Application")

End Select

If Err = 429 Then

Err.Clear

Select Case AppToInit

Case 1

Set GlobalWord = CreateObject("Word.Application")

Case 2

Set GlobalPower = CreateObject("Powerpoint.application")

Case 3

Set GlobalOutlook = CreateObject("outlook.application")

Case 4

Set GlobalInternet = CreateObject("InternetExplorer.Application")

Case 5

Set GlobalExcel = CreateObject("excel.Application")

End Select

End If

Else

Select Case AppToInit

Case 1

Set GlobalWord = CreateObject("Word.Application")

Case 2

Set GlobalPower = CreateObject("Powerpoint.application")

Case 3

Set GlobalOutlook = CreateObject("outlook.application")

Case 4

Set GlobalInternet = CreateObject("InternetExplorer.Application")

Case 5

Set GlobalExcel = CreateObject("excel.Application")

End Select

End If

End If

If Err <> 0 Then

Select Case AppToInit

Case 1

myerror = "Microsoft Word should be installed on this machine to view this demo"

Case 2

myerror = "Microsoft Power Point should be installed on this machine to view this demo"

Case 3

myerror = "Microsoft Outlook should be installed on this machine to view this demo"

Case 4

myerror = "Microsoft Interenet Explorer should be installed on this machine to view this demo"

Case 5

myerror = "Microsoft Excel should be installed on this machine to view this demo"

End Select

MsgBox myerror, vbCritical, "Error"

ObjectInitialize = False

End If

Exit Function

errorhandler:

MsgBox Err.Description, vbCritical, "Error"

End Function

Public Sub exportscreentoexcel()

Dim count1 As Integer

Dim tempposition1 As String

Dim b As Integer

Dim tempposition As String

Dim tempstring As String

Dim Count As Integer

Dim i As Integer

Dim mysheet As Object

Dim returnstring As String

Dim myrange As Object

'open excel and transfer ptpro screen to excel

If Not myapplication.ExcelEmbedded Then

GlobalExcel.Visible = True

GlobalExcel.Workbooks.Add

End If

returnstring = VBA.Trim(CStr(myapplication.GetScreenText(1, 1, 30, 30)))

If returnstring = "" Then Exit Sub

Set mysheet = GlobalExcel.Workbooks(1).Worksheets(1)

mysheet.Name = "PowerTerm Pro Screen"

Set myrange = mysheet.Range("A01", "m06")

myrange.Font.Bold = True

myrange.Font.Name = "Courier New"

myrange.Font.Size = 12

myrange.Columns("a:m").columnwidth = 20

myrange.Range("a1", "m1").Font.Color = vbGreen

myrange.Range("a2", "m2").Font.Color = vbBlue

myrange.Range("a3", "m3").Font.Color = vbYellow

myrange.Range("a4", "m4").Font.Color = vbCyan

myrange.Range("a5", "m5").Font.Color = vbRed

myrange.Range("a6", "m6").Font.Color = vbMagenta

myrange.NumberFormat = "@"

tempposition1 = 1

tempposition = 1

For i = 1 To VBA.Len(returnstring)

If Asc(Mid(returnstring, i, 1)) = 10 Then

Count = Count + 1

Select Case Count

Case 6

For b = 1 To VBA.Len(VBA.Mid(returnstring, tempposition, i))

If Asc(VBA.Mid(VBA.Mid(returnstring, tempposition, i), b, 1)) = 32 Or Asc(Mid(Mid(returnstring, tempposition, i), b, 1)) = 10 Then

count1 = count1 + 1

tempstring = VBA.Mid(VBA.Mid(returnstring, tempposition, i), tempposition1, b - tempposition1)

Do Until Asc(VBA.Mid(VBA.Mid(returnstring, tempposition, i), b, 1)) <> 32

b = b + 1

Loop

tempposition1 = b

'Set myrange = mysheet.Range("A" & IIf(count1 > 0 And count1 < 14, 6, IIf(count1 > 13 And count1 < 27, 7, IIf(count1 > 26 And coun1 < 40, 8, IIf(count1 > 39 And coun1 < 53, 9, IIf(count1 > 52 And count1 < 66, 10, IIf(count1 > 52, 11, 0)))))), "m" & IIf(count1 > 0 And count1 < 14, 6, IIf(count1 > 13 And count1 < 27, 7, IIf(count1 > 26 And coun1 < 40, 8, IIf(count1 > 39 And coun1 < 53, 9, IIf(count1 > 52 And count1 < 66, 10, IIf(count1 > 65, 11, 11)))))))

myrange.Cells(count1) = VBA.Trim(tempstring)

End If

Next b

End Select

tempposition = i + 1

End If

'

Next i

End Sub

Sub Appc(system, device)

Session.CommType = pt_Winappc

'The desired emulation session type is specified after the equals sign.

'The value must be one of the members of the EnumCommType.

Session.SystemName = CStr(system)

'The desired system name is specified as a char string in the parentheses

Session.DeviceName = CStr(device)

'The desired device name is specified as a char string in the parentheses

Session.Modify

Session.Open

Session.SessionName = CStr(device)

'The desired session name is specified as a char string in the parentheses

Keys

End Sub

' Variables that are used to interact with Excel from VBA

Public myexcelapp As Object

Public myworkbook As Object

Public myworksheet As Object

Public myrange As Object

Public Sub Bapi(host)

Session.CommType = pt_Bapi

'The desired emulation session type is specified after the equals sign.

'The value must be one of the members of the EnumCommType.

Session.HostName = CStr(host)

'The desired host name is specified as a char string in the parentheses

Session.Modify

Session.Open

Session.SessionName = CStr(host)

'The desired session name is specified as a char string in the parentheses

Keys

End Sub

Sub Comm(CommPort, Optional CommBaudRate As String = "", Optional protocolType As String = "", Optional phone As Variant = "")

CommPort = CInt(CommPort)

'The desired communication port number is specified as an integer in the parentheses.

phone = CStr(phone)

'The desired phone number is specified as an integer in the parentheses.

Session.CommType = pt_Com

'The desired communication type is specified following the equals sign.

'The value must be one of the members of the EnumCommType.

Session.CommPort = CommPort

'The desired communication port number is specified following the equals sign.

If CommPort < 1 Or CommPort > 128 Then

MsgBox "CommPort should be a number between 1-128"

Exit Sub

End If

If Len(CommBaudRate) <> 0 Then

'Establishes the baud rate for your transmission speed in the parentheses.

'The value must be one of the members of the EnumBaudRate.

If CommBaudRate <> "ptBR_14400" And CommBaudRate <> "ptBR_19200" And CommBaudRate <> "ptBR_300" And CommBaudRate <> "ptBR_115200" And CommBaudRate <> "ptBR_1200" And CommBaudRate <> "ptBR_1800" And CommBaudRate <> "ptBR_2000" And CommBaudRate <> "ptBR_2400" And CommBaudRate <> "ptBR_3600" And CommBaudRate <> "ptBR_38400" And CommBaudRate <> "ptBR_4800" And CommBaudRate <> "ptBR_57600" And CommBaudRate <> "ptBR_600" And CommBaudRate <> "ptBR_7200" And CommBaudRate <> "ptBR_9600" Then

MsgBox "Baud rate should be between ptBR_300 to ptBR_115200"

Exit Sub

Else

If CommBaudRate = "ptBR_14400" Then

Session.BaudRate = ptBR_14400

ElseIf CommBaudRate = "ptBR_19200" Then

Session.BaudRate = ptBR_19200

ElseIf CommBaudRate = "ptBR_300" Then

Session.BaudRate = ptBR_300

ElseIf CommBaudRate = "ptBR_115200" Then

Session.BaudRate = ptBR_115200

ElseIf CommBaudRate = "ptBR_1200" Then

Session.BaudRate = ptBR_1200

ElseIf CommBaudRate = "ptBR_1800" Then

Session.BaudRate = ptBR_1800

ElseIf CommBaudRate = "ptBR_2000" Then

Session.BaudRate = ptBR_2000

ElseIf CommBaudRate = "ptBR_2400" Then

Session.BaudRate = ptBR_2400

ElseIf CommBaudRate = "ptBR_3600" Then

Session.BaudRate = ptBR_3600

ElseIf CommBaudRate = "ptBR_38400" Then

Session.BaudRate = ptBR_38400

ElseIf CommBaudRate = "ptBR_4800" Then

Session.BaudRate = ptBR_4800

ElseIf CommBaudRate = "ptBR_57600" Then

Session.BaudRate = ptBR_57600

ElseIf CommBaudRate = "ptBR_600" Then

Session.BaudRate = ptBR_600

ElseIf CommBaudRate = "ptBR_7200" Then

Session.BaudRate = ptBR_7200

ElseIf CommBaudRate = "ptBR_9600" Then

Session.BaudRate = ptBR_9600

End If

End If

End If

If protocolType <> "" Then

'Establishes the communication protocol type before the unequal sign that is implemented.

'The FlowControl value must be one of the members of the EnumProtocolType.

If protocolType = "ptCP_None" Then

Session.FlowControl = PtermPro.EnumCommProtocol.ptCP_None

ElseIf protocolType = "ptCP_Hardware" Then

Session.FlowControl = PtermPro.EnumCommProtocol.ptCP_Hardware

ElseIf protocolType = "ptCP_XonXoff" Then

Session.FlowControl = PtermPro.EnumCommProtocol.ptCP_Xonxoff

Else: MsgBox "Protocol type should be ptCP_None, ptCP_Hardware or ptCP_Xonxoff"

End If

End If

Session.Modify

Session.Open

Keys

If phone <> "" Then

PtermPro.Send "ATDT" & phone & "^M"

End If

End Sub

Sub Cterm(Node)

Session.CommType = pt_Cterm

'The desired communication type is specified after the equals sign.

'The CommType value must be one of the members of the EnumCommType.

Session.NodeName = CStr(Node)

'The desired node name is specified inside the parentheses.

Session.Modify

Session.Open

Session.SessionName = CStr(Node)

'The desired session name is specified inside the parentheses.

Keys

End Sub

Sub Keys()

'The desired shortcut keys are specified inside the first set of parentheses

' followed by a 2nd set of parentheses containing the macro that is to be executed.

application.MapKeyToVbaMacro "ctrl+alt+x", "MaxModule.MaximizePro"

application.MapKeyToVbaMacro "ctrl+alt+r", "RestoreModule.RestorePro"

application.MapKeyToVbaMacro "ctrl+alt+n", "NotePadExeModule.NotePadExe"

application.MapKeyToVbaMacro "ctrl+alt+a", "TelnetModule.Telnet a"

application.MapKeyToVbaMacro "f2", "PrintModule.PrintScreen"

End Sub

Sub Lat(service)

Session.CommType = pt_Lat

'The desired communication type is specified after the equals sign

'The CommType value must be one of the members of the EnumCommType.

Session.ServiceName = CStr(service)

'The desired service name is specified inside the parentheses.

Session.Modify

Session.Open

Session.SessionName = CStr(service)

'The desired session name is specified inside the parentheses.

Keys

End Sub

Sub Mssna(luName)

Session.CommType = pt_Mssna

'The desired communication type is specified after the equals sign.

'The CommType value must be one of the members of the EnumCommType.

Session.luName = CStr(luName)

'The desired Lu name is specified inside the parentheses.

Session.Modify

Session.Open

Session.SessionName = CStr(luName)

'The desired session name is specified inside the parentheses.

Keys

End Sub

Sub Nwlat(user, service)

Session.CommType = pt_Nwlat

'The desired communication type is specified after the equals sign.

'The CommType value must be one of the members of the EnumCommType.

Session.UserName = CStr(user)

'The desired user name is specified inside the parentheses.

Session.ServiceName = CStr(service)

'The desired service name is specified inside the parentheses.

Session.Modify

Session.Open

Session.SessionName = CStr(service)

'The desired session name is specified inside the parentheses.

Keys

End Sub

Sub Nwsaa(server, user, service, luCategory As String, Optional luName As Variant = "")

Session.CommType = pt_Nwsaa_ipx

'The desired communication type is specified after the equals sign.

'The CommType value must be one of the members of the EnumCommType.

Session.ServerName = CStr(server)

'The desired server name is specified inside the parentheses.

Session.UserName = CStr(user)

'The desired user name is specified inside the parentheses.

Session.ServiceName = CStr(service)

'The desired service name is specified inside the parentheses.

If Len(luCategory) <> 0 Then

'The desired Lu category is specified inside the parentheses.

'The luCategory value must be one of the members of the EnumLuCategory.

If luCategory = "ptLu_Dedicated" Then

Session.luCategory = ptLu_Dedicated

ElseIf luCategory = "ptLu_Pooled" Then

Session.luCategory = ptLu_Pooled

ElseIf luCategory = "ptLu_Public" Then

Session.luCategory = ptLu_Public

Else

MsgBox "LuCategory Value should be ptLu_Dedicated, ptLu_Pooled or ptLu_Public"

Exit Sub

End If

End If

If luName <> "" Then

'The Lu name is specified before the unequal sign.

Session.luName = CStr(luName)

'The desired Lu name is specified as a char string in the parentheses.

End If

Session.Modify

Session.Open

Session.SessionName = CStr(luName)

'The desired session name is specified as a char string in the parentheses.

Keys

End Sub

Sub Nwsaatcp(server, user, service, luCategory As String, Optional luName As Variant = "")

Session.CommType = pt_Nwsaa_TCPIP

'The desired communication type is specified after the equals sign.

'The CommType value must be one of the members of the EnumCommType.

Session.ServerName = CStr(server)

'The desired server name is specified inside the parentheses.

Session.UserName = CStr(user)

'The desired user name is specified inside the parentheses.

Session.ServiceName = CStr(service)

'The desired service name is specified inside the parentheses.

'The luCategory value must be one of the members of the EnumLuCategory.

If Len(luCategory) <> 0 Then

If luCategory = "ptLu_Dedicated" Then

Session.luCategory = ptLu_Dedicated

ElseIf luCategory = "ptLu_Pooled" Then

Session.luCategory = ptLu_Pooled

ElseIf luCategory = "ptLu_Public" Then

Session.luCategory = ptLu_Public

Else

MsgBox "LuCategory Value should be ptLu_Dedicated, ptLu_Pooled or ptLu_Public"

Exit Sub

End If

End If

If luName <> "" Then

Session.luName = CStr(luName)

'The desired Lu name inside the parentheses is converted to a char string.

End If

Session.Modify

Session.Open

Session.SessionName = CStr(luName)

'The session name receives the value from inside the parentheses.

Keys

End Sub

Public Sub Ole()

Dim cel(1 To 3) As String

Dim i As Integer

Dim row As Integer

For i = 1 To 3

row = i + 3

cel(i) = Left(application.GetRectText(row, 10, row, 15), Len(application.GetRectText(row, 10, row, 15)) - 1)

Next i

'Create Excel object

Set myexcelapp = CreateObject("excel.application")

'Add new workbook

myexcelapp.Workbooks.Add

'Set global variables

Set myworkbook = myexcelapp.Workbooks(1)

Set myworksheet = myworkbook.Worksheets(1)

Set myrange = myworksheet.Range("a1", "a4")

myrange.Font.Bold = True

myrange.Font.Name = "Courier New"

myrange.Font.size = 20

myrange.Columns("a").columnwidth = 120

myrange.Cells(1).Font.Color = vbGreen

myrange.Cells(2).Font.Color = vbBlue

myrange.Cells(3).Font.Color = vbYellow

myrange.Cells(4).Font.Color = vbCyan

myrange.Cells(4, 1).Formula = "=sum(a1:a3)"

For i = 1 To 3

myrange(i) = cel(i)

Next i

'Make Excel visible

myexcelapp.Visible = True

End Sub

Sub Printer()

Dim Name As String

Name = application.GetPrinterName

If Left(Name, 5) = "EPSON" Then

application.StatusMessage "Selected Printer is EPSON " & Name

application.OpenPrinterFile "epson.prt"

ElseIf Left(Name, 3) = "IBM" Then

application.StatusMessage "Selected Printer is IBM " & Name

application.OpenPrinterFile "ibm.prt"

ElseIf Left(Name, 2) = "HP" Then

application.StatusMessage "Selected Printer is HP " & Name

application.OpenPrinterFile "hp.prt"

Else

application.StatusMessage "Selected Printer is DEC-LA75 ($PrinterName)"

application.OpenPrinterFile "decla75.prt"

End If

End Sub

Sub Telnet(host, Optional telPort As Variant = "")

telPort = CStr(telPort)

'The desired telport number is specified as an integer in the parentheses

Session.CommType = pt_Telnet

'The desired communication type is specified as an integer in the parentheses.

'The CommType value must be one of the members of the EnumCommType.

Session.HostName = CStr(host)

'The desired host name is specified as a char string in the parentheses.

If telPort <> "" Then

Session.TelnetPort = telPort

End If

Session.Modify

Session.Open

Session.SessionName = CStr(host)

'The desired session name is specified in the parentheses.

Keys

End Sub

Sub Tn3270(host, Optional telPort As Variant = "", Optional luName As Variant = "")

telPort = CStr(telPort)

'The desired telport number is specified as an integer in the parentheses.

luName = CStr(luName)

'The desired lu name is specified in the parentheses.

Setup.EmulationType = pt3270_Display

'The desired emulation session type is specified after the equals sign.

'The EmulationType value must be one of the members of the EnumEmulationType.

Session.CommType = pt_Tn3270

'The desired communication type is specified after the equals sign.

'The CommType value must be one of the members of the EnumCommType.

Session.HostName = CStr(host)

'The desired host name is specified in the parentheses.

If telPort <> "" Then

Session.TelnetPort = telPort

End If

If luName <> "" Then

Session.luName = luName

End If

Session.Modify

Session.Open

Session.SessionName = host

'The desired session name is specified after the equals sign.

Keys

End Sub

Sub Tn3270e(host, Optional telPort As Variant = "", Optional luName As Variant = "")

telPort = CStr(telPort)

'The desired telport number is specified as an integer in the parentheses.

luName = CStr(luName)

'The desired lu name is specified in the parentheses.

Setup.EmulationType = pt3270_Display

'The desired emulation session type is specified after the equals sign.

'The EmulationType value must be one of the members of the EnumEmulationType.

Session.CommType = pt_Tn3270

'The desired communication type is specified after the equals sign.

'The CommType value must be one of the members of the EnumCommType.

Session.HostName = CStr(host)

'The desired host name is specified in the parentheses.

Session.UseTN3270EProtocol = True

'True/False after the equals sign specifies whether to use the TN3270 protocol.

If telPort <> "" Then

Session.TelnetPort = telPort

End If

If luName <> "" Then

Session.luName = luName

End If

Session.Open

Session.SessionName = CStr(host)

'The desired session name is specified after the equals sign.

Keys

End Sub

Sub Tn5250(host, Optional telPort As Variant = "")

telPort = CStr(telPort)

'The desired telport number is specified as an integer in the parentheses.

Setup.EmulationType = pt5250_Display

'The desired emulation session type is specified after the equals sign.

'The EmulationType value must be one of the members of the EnumEmulationType.

Session.CommType = pt_Tn5250

'The desired communication type is specified after the equals sign.

'The CommType value must be one of the members of the EnumCommType.

Session.HostName = CStr(host)

'The desired host name is specified in the parentheses.

If telPort <> "" Then

Session.TelnetPort = telPort

End If

Session.Modify

Session.Open

Session.SessionName = CStr(host)

'The desired session name is specified after the equals sign.

Keys

End Sub

Sub ReceiveFile()

Dim b As Boolean

Session.CommType = pt_Co

'The desired communication type is specified after the equals sign.

'The CommType value must be one of the members of the EnumCommType.

Session.CommPort = 0

'The desired communication port is specified after the equals sign.

Session.BaudRate = ptBR_9600

'Establishes the baud rate for your transmission speed after the equals sign.

'The BaudRate value must be one of the members of the EnumBaudRates.

Session.Parity = ptPar_8_Odd

'Establishes the parity after the equals sign.

'The Parity value must be one of the members of the EnumParity.

Session.StopBits = ptSB_1

'Establishes the stop bits after the equals sign.

'The StopBits value must be one of the members of the EnumStopBits.

Session.FlowControl = ptCP_Xonxoff

Session.Modify

b = Session.Open()

If b = False Then

Exit Sub

Else

' 1111111 is the phone number of the host you are connecting to PtermPro.Send "atdt1111111"

' xxxx are the user name and the password to login to the host

PtermPro.Wait 3

PtermPro.Send "xxxx" & VBA.vbCrLf

PtermPro.Wait 3

PtermPro.Send "xxxx" & VBA.vbCrLf

PtermPro.Send "kermit" & VBA.vbCrLf

PtermPro.Wait 2

PtermPro.Send "send new" & VBA.vbCrLf

PtermPro.Wait 2

PtermPro.ReceiveFile pt_Kermit, "aFile.txt"

End If

PtermPro.Send "exit" & VBA.vbCrLf

End Sub

Sub SendFile(host As String, user As String, Optional password As String = "")

Dim b As Boolean

Session.CommType = pt_Telnet

'The desired communication type is specified after the equals sign.

'The CommType value must be one of the members of the EnumCommType.

Session.HostName = host

'The desired host name is specified in the parentheses.

Session.Modify

b = Session.Open

If b = False Then

PtermPro.Exit

Else

PtermPro.Wait 3

PtermPro.Send user & VBA.vbCrLf

If Len(password) > 0 Then

PtermPro.Wait 2

PtermPro.Send password & VBA.vbCrLf

End If

PtermPro.Wait 2

PtermPro.Send "kermit" & VBA.vbCrLf

' ????Transfers files in Kermit mode.

PtermPro.Wait 2

PtermPro.Send "receive" & VBA.vbCrLf

' ??Transfers files in Kermit mode.

PtermPro.Wait 2

PtermPro.SendFile pt_Kermit, "aFile.txt"

' ???Transfers files in Kermit mode.

End If

End Sub

Public Sub RestorePro()

application.RestoreWindow

End Sub

Public Sub PrintScreen()

application.PrintScreen

End Sub

Public Sub NotePadExe()

Dim myretval As Long

Dim mylen As Long

Dim mybuff As String

mybuff = VBA.Space(250)

mylen = VBA.Len(mybuff)

myretval = GetSystemDirectory(mybuff, mylen)

If mybuff <> "" Then

If Len(Dir(Left(RTrim(mybuff), Len(RTrim(mybuff)) - 1) & "\" & "notepad.exe")) <> 0 Then

myretval = Shell(Left(RTrim(mybuff), Len(RTrim(mybuff)) - 1) & "\" & "notepad.exe", vbNormalFocus)

Else

MsgBox "Please check if notepad installed on this mashine", vbInformation, "Error"

End If

End If

End Sub

Internet

Launches the user’s internet browser to a desired internet site.

Whether the application is standalone or embedded depends upon the PowerTerm Pro General Settings.

Favorites List: Your own preferred list of Web pages for easy access.

URL: An Internet address typically starts with a protocol name, followed by the name of the organization that maintains the site.

Auto Login

Performs an effortless login to the host or logoff from the host. The scheduler can automatically perform this task at any designated time in the future.

Host: Specifies the host computer name or its IP address.

User: Specifies the user name.

Password: Specifies the user’s password.

Wait For: Specifies the text (for example: Login) that must received from the remote host and displayed before sending to the remote host the user name.

Wait For: Specifies the text (for example: Password) that must received from the remote host and displayed before sending to the remote host the user’s password.

Power Terminal

Power Terminal sends the PowerTerm Pro emulation screen display to various destinations.

Send Screen to Word

Screen data is displayed in Word*.

Send Screen to Outlook

Screen data is imported into Outlook either as body text or as an attached Word file.

Send Screen to Browser

Screen data is displayed by the default browser*.

Send Screen to Power Point

Screen data is displayed in Power Point.

Modify PowerTerm Pro from Word

Modifies PowerTerm Pro’s size, title and position from within a Word document.

Print Screen

Sends Screen data to the default printer.

* Whether the application is standalone or embedded depends upon the PowerTerm Pro General Settings.

Option Preferences

Minimize

Minimizes the application screen.*

Maximize

Maximizes the application screen.*

Mail Recipient

Inserts the data display from the emulation screen in the body of the email.

Mail Recipient (As Attachment)

Inserts the data display from the emulation screen in a Word document and attaches it to an email.

* Whether the application is standalone or embedded depends upon the PowerTerm Pro General Settings.

System Info

This screen demonstrates how VBA assists you in interacting with the API. API (Acronym for application programming interface), a set of routines that an application programmer uses to request and carry out lower-level services performed by a computer’s operating system. These maintenance chores are performed by the computer’s operating system, and an API provides the program with a means of communicating with the system, telling it which system-level task to perform and when.

System Info displays a list of all visible windows operating on the system and their relative positions. Double-clicking any one of the items on the list will open up that program.

 Double-click on the desired application from the All Visible Windows list and the selected application is displayed

The position of the selected application is displayed in the Window Position fields.

 Click on System Information to open up System information window.

FTP

Provides a user-friendly interface to connect to a FTP host.

Host: Specifies the host computer name or its IP address.

User: Specifies the user name.

Password: Specifies the user’s password.

Multi Session Control

This screen demonstrates how VBA assists you in interacting with multiple screen sessions of PowerTerm Pro. It displays a list of all visible PowerTerm Pro sessions operating on the system and their relative positions, size and title. Selecting any one of the items on the list will display this information. The relative positions, size and title can be modified.

 The target session must first be connected to a host for the transfer to be successful.

Position

Left: Specifies the left alignment of the PowerTerm Pro session window.

Top: Specifies the top alignment of the PowerTerm Pro session window.

Size

Height: Specifies the height of the PowerTerm Pro session window.

Width: Specifies the width of the PowerTerm Pro session window.

Title: Specifies the text that appears on the title bar of the PowerTerm Pro session window.