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!

RE: Selecting Characters On Screen / Copy To Windows Clipboard

Status
Not open for further replies.

Douglazb

Technical User
Jul 25, 2002
1
US

Can anyone provide a sample code illustrating how to copy text from Extra! Personal Client (Version 6.1 “International” to the windows clipboard? We need to automate repetitious copying and pasting between different screens in Extra! (or other Microsoft programs).

Thanks in advance

Douglas

Doug.Arnold@Safelite.com
or
Sy.Khamvongsa@Safelite.com
 
Hi Doug,
This is what I've been using to copy 'screens' from attachmate and pasting it to excel. It should work with any app that supports vba. First, is the class that encapsulates attachmates functions.. btw, am using attachmate v6.5.. for v6.1 the type names might change...


cExtraAutomation.cls
--------------------

Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private appExtra As EXTRA.EXTRASystem
Private appSession As EXTRA.EXTRASession
Private appScreen As EXTRA.EXTRAScreen
Private appOIA As EXTRA.ExtraOIA

Private g_HostSettleTime As Integer
Private OldSystemTimeout As Integer
Private LineBuffer As String
Private initOK As Boolean

Private Sub Class_Initialize()
On Error GoTo init_err_handler

Set appExtra = New EXTRA.EXTRASystem
'Set appExtra = CreateObject("EXTRA.EXTRASystem")
Set appSession = appExtra.ActiveSession
Set appScreen = appSession.Screen
Set appOIA = appScreen.OIA

appSession.Visible = True

g_HostSettleTime = 300 ' milliseconds

OldSystemTimeout = appExtra.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
appExtra.TimeoutValue = g_HostSettleTime
End If

ClearBuffer
initOK = True

init_exit_point:
Exit Sub

init_err_handler:
initOK = False
GoTo init_exit_point

End Sub

Private Sub Class_Terminate()

If Not (appExtra Is Nothing) Then
appExtra.TimeoutValue = OldSystemTimeout
End If
Set appExtra = Nothing
Set appSession = Nothing
Set appScreen = Nothing
Set appOIA = Nothing

End Sub

Public Sub SendKeys(strKeys As String)

appScreen.SendKeys strKeys
WaitHostQuiet

End Sub

Public Sub WaitHostQuiet()

Do Until appScreen.WaitHostQuiet(g_HostSettleTime)
Sleep g_HostSettleTime
Loop

End Sub

Public Sub CopyToClipboard()

appScreen.SelectAll
WaitHostQuiet
appScreen.Copy

End Sub

Public Function GetString(row As Integer, column As Integer, length As Integer)

GetString = appScreen.GetString(row, column, length)

End Function

Public Sub CopyToScreenBuffer(Optional x1, Optional y1, _
Optional x2, Optional y2)
Debug.Assert (x1 > x2 And y1 < y2)

' internal buffer requires row x col bytes
ClearBuffer
Dim Index As Integer, NewLine As String, RowData As String, _
ix1 As Integer, iy1 As Integer, ix2 As Integer, iy2 As Integer

NewLine = Chr$(13) + Chr$(10)

If (IsMissing(x1) Or IsMissing(x2) Or IsMissing(y1) Or IsMissing(y2)) Then
ix1 = 1: iy1 = 1: ix2 = 80: iy2 = Rows
Else
ix1 = x1: iy1 = y2: ix2 = x2: iy2 = y2
End If

For Index = y1 To y2
RowData = GetString(Index, x1, x2)
LineBuffer = LineBuffer & RowData & NewLine
Next

' For Index = 1 To Rows
' RowData = GetString(Index, 1, 80)
' LineBuffer = LineBuffer & RowData & NewLine
' Next

End Sub

Public Sub CACSSleep()
Sleep g_HostSettleTime
End Sub
Private Sub ClearBuffer()
LineBuffer = &quot;&quot;
End Sub

Public Sub MoveTo(row As Integer, col As Integer)
appScreen.MoveTo row, col
End Sub

Public Property Get Rows() As Integer
Rows = appScreen.Rows
End Property

Public Property Get Cols() As Integer
Cols = appScreen.Cols
End Property

Public Property Get ScreenBuffer() As String
ScreenBuffer = LineBuffer
End Property

Public Property Get EXTRASystem() As Object
EXTRASystem = appExtra
End Property

Public Property Get EXTRASession() As Object
EXTRASession = appSession
End Property

Public Property Get EXTRAScreen() As Object
EXTRAScreen = appScreen
End Property

Public Property Get ConnectionStatus() As String
Dim Status As String

Select Case appOIA.ConnectionStatus
Case EXTRA.OiaConnectionStatusConstants.xAPP_OWNED
Status = &quot;Live connection&quot;
Case EXTRA.OiaConnectionStatusConstants.xSSCP
Status = &quot;SSCP&quot;
Case EXTRA.OiaConnectionStatusConstants.xUNOWNED
Status = &quot;Not Connected&quot;
Case Else
Status = &quot;ERROR!&quot;
End Select

ConnectionStatus = Status

End Property

Public Property Get IsInitialized() As Boolean
IsInitialized = initOK
End Property

Example 1: An Excel Macro
--------------------------

Sub Test()

Dim cCACS As cExtraAutomation
Set cCACS = New cExtraAutomation

'To copy to clipboard
cCACS.CopyToClipboard

'Move to another screen
cCACS.SendKeys(&quot;<pf4>&quot;)

'To copy to internal screen buffer
cCACS.CopyToScreenBuffer

'Copy from clipboard
ActiveSheet.Paste

'Copy from Screen Buffer
ActiveCell.FormulaR1C1 = cCACS.ScreenBuffer

end sub



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top