Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendKey for Enter from vbscript to Attachmate

Status
Not open for further replies.

RitaG

Programmer
Aug 6, 2012
11
US
Hi,

I have a requirement, which requires connecting to Attachmate using VBScripts. My problem is fairly basic. I have tried a LOT of things, but I just can't get the SendKeys operation for Enter to work.

I have tried :

' gobjTerminal is the Terminal object for the current session
' Set gobjScreen = gobjTerminal.Screen

1. gobjScreen.SendKeys ("<Enter>")
2. gobjScreen.SendControlKeys_Transmit
3. gobjScreen.TransmitTerminalKey ([ENTER])
4. gobjScreen.TransmitTerminalKey (289)
5. Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{ENTER}"
6. gobjScreen.SendKeys "{ENTER}"

None seem to work. I am fairly new to Attachmate, right now I'm completely lost. Any assistance would be highly appreciated !!

PS :- A doubt :
in many posts I have seen the following line
Sess0.Screen.SendKeys ("<ENTER>")

What is Sess0 ? And what is its definition ?
 
I'm sorry ...

its actually :
2. gobjScreen.SendControlKeys ControlKeyCode_Transmit

 
Any help please ?? Really desperate... Cannot do any sendkey function like F11 or F8 either....
 
hi,

Attachmate Extra has no terminal object!

To get you started...
Code:
    Set oSystem = CreateObject("Extra.System")
'[highlight]this happens to be where my emulator is stored[/highlight]   
    Set oSess = oSystem.Sessions.Open("C:\Program Files\E!PC\Sessions\Mainframe.edp")

    With oSess
        .Visible = True
        .WindowState = xNORMAL
    End With

    Set oScrn = oSess.SCREEN

    oScrn.SendKeys ("<ENTER>")


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I am using Attachmate Reflection Suite 4x 2011, running the script in QTP. I really new to this so I'm really sure if this is different from Attachmate Extra.

This is how I am creating the object:
Set gobjApplication = CreateObject("Attachmate_Reflection_Objects_Framework.ApplicationObject")

.Sessions.Open throws an error saying the code is not supported.
 
Use your HELP feature to find the available objects and methods.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The HELP ain't very helpful :/

These are members of IBMScreen objects (From Attachmate HELP):
.SendControlKeySync ControlKeyCode_Transmit
.SendControlKeys ControlKeyCode_Transmit

But these dont work either. Nothing happens on the screen. No error is thrown either.
 
Can't help you with Reflection.

I'd only say, start with the application object and work down.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi,

I wrote this a few years ago to automate working with Extra

Its basically a wrapper Class Module which you can add to your Project,

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
To use it just add a line like to your code dont forget to add a reference to Extra!

Private WithEvents Tool As clsExtra ' declare (Tool is just a name)

then just say something like Tool. and it will list the methods in the class, or you can add your own methods

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Here's the Code for the class, just add a class to your project and paste this into it. Worked for me for years...

Option Explicit

' *********************************************************************************
' clsEasyExtra, Steve Carr 15/9/03. Please modify or distribute freely.
' A simple class designed to allow you to i/face your VB application with Extra
' I have only inserted some common methods which I think you may find useful
' You may of course insert as many as you like, or modify the code to suit your
' own application. DONT FORGET TO SET UP A REFERENCE TO THE EXTRA OBJECT LIBRARY
' *********************************************************************************

Private objSystem As EXTRA.ExtraSystem ' declare some objects
Private objSession As EXTRA.ExtraSession
Private objScreen As EXTRA.ExtraScreen
Private objSessions As EXTRA.ExtraSessions


' Class Event Handlers

Private Sub Class_Initialize()

On Error GoTo Class_Initialize_Error

' Establish connection to Host via a valid Session
Dim intSessionCount As Integer

Set objSystem = New EXTRA.ExtraSystem
Set objSessions = New EXTRA.ExtraSessions


objSystem.TimeoutValue = 500

For intSessionCount = 1 To objSystem.Sessions.Count

Set objSession = objSystem.Sessions.Item(intSessionCount)
Set objScreen = objSession.Screen
objSession.Visible = True

Exit Sub

Next

Exit Sub

Class_Initialize_Error:
MsgBox "Valid Host Session not Available", vbCritical, "Critical Application Error"
End Sub

Private Sub Class_Terminate()

On Error Resume Next

Set objSystem = Nothing ' dispose
Set objSession = Nothing
Set objScreen = Nothing

End Sub

' General class methods

'Sends a Reset to Host

Public Sub Reset()

objScreen.SendKeys "<pf24>"
WaitForHost 1

End Sub

'Make Host Screen visible

Public Sub OpenSession()

objSession.NavigateTo Me

End Sub



Public Sub CloseSession()


objSession.Close

End Sub

Public Sub Show()

objSession.Visible = True

End Sub

'Make Host Screen invisible

Public Sub Hide()

objSession.Visible = False

End Sub

'Host Page Forward

Public Sub PageForward()

objScreen.SendKeys "<pf8>"
WaitForHost 1

End Sub

'Host Page Back

Public Sub PageBack()

objScreen.SendKeys "<pf7>"
WaitForHost 1

End Sub

'Save Host Screen

Public Sub Save()

objScreen.SendKeys "<pf20>"
WaitForHost 1

End Sub

'Recall saved Screen

Public Sub Recall()
objScreen.SendKeys "<pf21>"
WaitForHost 1

End Sub

'Goto Home ie. Screen position 01/02

Public Sub Home()

objScreen.SendKeys "<home>"
WaitForHost 1

End Sub

'Send Enter to Host

Public Sub Enter()

objScreen.SendKeys "<enter>"
WaitForHost 1

End Sub

'Send PF9 to Host

Public Sub A1()

objScreen.SendKeys "<pf9>"
WaitForHost 1

End Sub

'Delete line

Public Sub EraseEOF()

objScreen.SendKeys "<EraseEOF>"

End Sub


'Send data to Host with screen position x,y

Public Sub SendMessageParams(ByVal message As String, X As Integer, y As Integer)
objScreen.PutString message, X, y
End Sub

'Send data to Host without screen position

Public Sub SendMessage(message As String)
objScreen.PutString message
End Sub

'Send a command to Host

Public Sub SendCommand(command As String)
objScreen.SendKeys command
WaitForHost 1
End Sub


'Read text at cursor position

Public Function GetText(X As Integer, y As Integer, chars As Integer) As String

GetText = objScreen.GetString(X, y, chars)

End Function


'Wait for x seconds until host settles

Public Sub WaitForHost(seconds As Integer)

Do While objScreen.OIA.XStatus = 5
objScreen.WaitHostQuiet seconds ' x milliseconds
Loop

End Sub

' Minimize Host Screen

Public Sub MinimizeScreen()

objSession.WindowState = xMINIMIZED

End Sub

' Maximize Host Screen

Public Sub MaximizeScreen()

objSession.WindowState = xMAXIMIZED

End Sub

' Send Clear to Host

Public Sub Clear()

objScreen.SendKeys ("<clear>")

End Sub

' Restore Host screen to Normal

Public Sub RestoreScreen()

objSession.WindowState = xNORMAL

End Sub

*********************************************************************************************************************


Hope it helps,

Steve...

!ExtraDunce
 
Hi,,

oops!!

I missed off one really important bit, in your startup form or Sub Main() you'll need to instantiate the class like below

Tool = New clsExtra

then you can use the intellisense Tool. and it should drop you a list of the methods in the class.

This was written for an IBM Host Session, I've got a couple of bits and peices for a Unix Host if you need any more.

Steve


!ExtraDunce
 
Hey Steve,

As mentioned earlier, I am using Attachmate Reflection Suite 4x 2011. Is this the same as the version you are talking about ?
Instead of a Session object, an Application object gets created.. so I really dont know how to go forward with that.
 
BTW, using a WAIT method for a specified time, is like saying, "When I get to the traffic light, I'll wait for 10 seconds, then I'll go!" Sometimes you'll be waiting TOO long. Sometimes you'll not be waiting long enough (and loose data)!!!
[tt]
1. use MoveRelative to move the cursor away from the screen's Cursor rest Postion.

2. Issue the Control Key String using SendKeys

3. Loop until the cursor appears at the screen's Cursor rest Postion.
[/tt]
Code:
   With oScreen
        .MoveRelative 1, 1, 1
        .SendKeys ("<enter>")
        Do Until .WaitForCursor(3, 19)
            DoEvents
        Loop
   End With



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks a lot, Steve and Skip.

And I agree about the "WAIT". I was wondering how to go around that, so thanks again Skip :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top