Print Page | Close Window

Alternative to Session.Copy

Printed From: Rocket Software
Category: AccuTerm Knowledge Base (read only)
Forum Name: Scripting & Automation
Forum Description: Customize and control AccuTerm using scripts and automation
URL: https://forum.asent.com/forum_posts.asp?TID=2705
Printed Date: March 28 2024 at 4:18am
Software Version: Web Wiz Forums 12.03 - http://www.webwizforums.com


Topic: Alternative to Session.Copy
Posted By: kbdav
Subject: Alternative to Session.Copy
Date Posted: January 22 2019 at 7:37am
I use
s = Session.getText()
quite often to grab a single line from the terminal. This works great and it bypasses the clipboard.

However, I am now in the need of grabbing multiple lines from a session, and the only way I know to do this is by using 
Session.Copy()
s = Clipboard
as there is an option for top and bottom arguments (in .getText(), there is only the argument for a single line).

Is there any method that would effectively do something like this (without the syntax error):

Dim s As String
s = Session.Copy(0,1,10,2)
' 1 = top line, 2 = bottom line - Could contain vbCrLf like .Copy or any other delimiter 

I do not like to use the clipboard because I have had issues in the past with AccuTerm locking the clipboard up and me having to add extra code to restore the original clipboard's contents before the .Copy, such as:

Dim sOldClipboard as String, s as string
sOldClipboard = Clipboard
Session.Copy()
s = Clipboard
Clipboard sOldClipboard 

and is rather inconvenient, especially considering that getText() only requires a single line. I've tried to find better documentation of session.getBlock(), but doesn't appear to do what I need or I just can't find the proper way to use it.

Btw, I am (still) using AccuTerm 2K2 Ermm



Replies:
Posted By: kbdav
Date Posted: January 22 2019 at 8:00am
In the meantime, I created this function to mimic what I am wanting to do, but if someone knows of a native way to accomplish this I am all ears!

Function GetText2(ByVal Left%, ByVal Top%, ByVal Right%, ByVal Bottom%) As String
    Dim i As Integer, retArr() As String
    ReDim retArr(Top To Bottom)
    For i = Top To Bottom
        retArr(i) = pubSession.GetText(Left, i, Right - Left + 1)
    Next
    GetText2 = Join(retArr, vbCrLf)
End Function

(pubSession is essentially just a global variable / Session obj I use so I don't have to pass the session as an argument between Subs)


Posted By: PSchellenbach
Date Posted: January 22 2019 at 2:21pm
Another alternative would be to select the area you want to get, then use the Selection property:
Function GetText3(Session As Session, ByVal Left As Integer, ByVal Top As Integer, ByVal Right As Integer, ByVal Bottom As Integer) As String
    Dim Lines As String
    Session.SetSelection Left,Top,Right,Bottom
    Lines = Session.Selection
    Session.ClearSelection
    GetText3 = Lines
End Function
Thanks, Pete



Posted By: kbdav
Date Posted: January 23 2019 at 9:47am
Ahh, a method without a loop, nice!

Thanks for the response



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.03 - http://www.webwizforums.com
Copyright ©2001-2019 Web Wiz Ltd. - https://www.webwiz.net