×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Wrap Pasted Text In Attacmate

Wrap Pasted Text In Attacmate

Wrap Pasted Text In Attacmate

(OP)
I constantly paste from Outlook to Attachate.  If the cpoied text is longer than the space available in Attachmate it does not continue to the next line.  I want to write a macro that will wrap the text.  My idea was to use the screen coordinates and maybe loop it.  I am very new to VB so thank you in advance for bearing with me.    

RE: Wrap Pasted Text In Attacmate


hi,

Use PutString!

You have to consider 1) the COLUMN where your string will start, 2) the number of characters on your screen.

Then you can write a loop to calculate how long the PutString can be and not get chopped off.  You also need to know in what column the next line starts.  Should be pretty simple.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
Awesome! Thank you. I am running into the issue of syntax with the PutString.  I can't figure out the syntax to Put the copied text rather than what I tell it to Put.    

RE: Wrap Pasted Text In Attacmate



You'll have to access the ClipBoard to get the text into a variable.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
Ok this is what I have.

' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
    Dim Sessions As Object
    Dim System As Object
    Set System = CreateObject("EXTRA.System")   ' Gets the system object
    If (System Is Nothing) Then
        MsgBox "Could not create the EXTRA System object.  Stopping macro playback."
        Stop
    End If
    Set Sessions = System.Sessions

    If (Sessions Is Nothing) Then
        MsgBox "Could not create the Sessions collection object.  Stopping macro playback."
        Stop
    End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
    g_HostSettleTime = 3000     ' milliseconds

    OldSystemTimeout& = System.TimeoutValue
    If (g_HostSettleTime > OldSystemTimeout) Then
        System.TimeoutValue = g_HostSettleTime
    End If

' Get the necessary Session Object
    Dim Sess0 As Object
    Set Sess0 = System.ActiveSession
    If (Sess0 Is Nothing) Then
        MsgBox "Could not create the Session object.  Stopping macro playback."
        Stop
    End If
    If Not Sess0.Visible Then Sess0.Visible = True
    Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
    
' The important stuff
    
    Dim stuffToPaste As String
    stuffToPaste = Clipboard.GetText()
    
    Sess0.Screen.PutString stuffToPaste, Sess0.Screen.Cursor
    


   

    System.TimeoutValue = OldSystemTimeout
    
End Sub


For some reason it's not reading what is pasted.  It's telling me that the putstring line is not a valid method or function.

RE: Wrap Pasted Text In Attacmate



CODE

    Dim MyDataObj As MSForms.DataObject

    Set MyDataObj = New DataObject

    MyDataObj.GetFromClipboard

    MsgBox MyDataObj.GetText(1)

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate



If that does not work then try this...

CODE


'credit to http://akihitoyamashiro.com/en/VBA/LateBindingDataObject.htm

    Dim MyDataObj As Object

    Set MyDataObj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

    MyDataObj.GetFromClipboard

    MsgBox MyDataObj.GetText(1)

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
I was able to get the previous code to work.  I'm not sure where to get the "code" section for the post, but here it is.

    Dim stuffToPaste As String
    
    stuffToPaste = Clipboard.GetText()
    
    Sess0.Screen.PutString stuffToPaste, Cursor

I just removed the Sess0.Screen for the cursor because it was looking for that entire function, which did not exist.   
No it's on to figuring out the loop.  I'm sure i'll be bugging you more.
Thank you so much for the help so far!!

RE: Wrap Pasted Text In Attacmate

(OP)
Ok, I don't even know where to start.  Would you beable to point me in the right direction?  I'm a newbie at VB.

RE: Wrap Pasted Text In Attacmate



Quote (SkipVought):

You have to consider 1) the COLUMN where your string will start, 2) the number of characters on your screen.

...You also need to know in what column the next line starts.  
Do we know THAT and if so WHAT?

 

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate



CODE

Sub test()
    Dim iColStrt As Integer, iNbrCols As Integer, iColNxt As Integer
    Dim MyDataObj As Object, sCopied As String, iRow As Integer, iCol As Integer
    Dim p1 As Integer, pLen As Integer

    Set MyDataObj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

    MyDataObj.GetFromClipboard
    
    sCopied = MyDataObj.GetText(1)
    
    iColStrt = 70   'column where the 'paste' starts
    iRow = 1        'row where the 'paste' starts
    iNbrCols = 80   'number of columns on screen
    iColNxt = 60    'column where the 'paste' wraps to on the next line and following
    
    p1 = 1                      'parsing pointer start
    pLen = iNbrCols - iColStrt  'parsing string length
    iCol = iColStrt             'column to 'paste'
    Do While p1 < Len(sCopied)
        Sess0.Screen.PutString Mid(sCopied, p1, pLen), iRow, iCol
        p1 = p1 + pLen              'next parsing pointer start
        pLen = iNbrCols - iColNxt   'next parsing string length
        iCol = iColNxt              'next columns to 'passte'
        iRow = iRow + 1             'next row to 'paste'
    Loop
    Set MyDataObj = Nothing
End Sub
 

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
I took this code snippet from somwhere else and tried to modify it to fit my needs.  I need to start at 5,7 and the last on that line is 5,76.  The area goes to 40,76.

   

CODE

Dim stuffToPaste As String
    stuffToPaste = Clipboard.GetText()
    
    Dim stringLength As Long
    stringLength = Len(stuffToPaste)
    
    Dim endOfWord As Double
    endOfWord = 0
    

        
    While stringLength > 65
        
    endOfWord = InStr(startPosition, stuffToPaste, " ")
    If endOfWord = 0 Then
        Sess0.Screen.PutString 5, 7 = Mid(stuffToPaste, startPosition, stringLength)
GotToDone:
    Else
        Sess0.Screen.PutString 6, 7 = Mid(stuffToPaste, startPosition, (endOfWord - startPosition))
        startPosition = endOfWord + 1
Wend
I don't think this will work yet.   

RE: Wrap Pasted Text In Attacmate

(OP)
Again, thank you!!! I was able to get it to work with that logic.  I was able to tweak it to make it start on the cursor so if the macro is run more than once it doesn't replace the previous.

CODE

iColStrt = Sess0.Screen.Col          
iRow = Sess0.Screen.Row              
iNbrCols = 75                    
iColNxt = iColStrt + 1              

parseStart = 1                          
parseLen = iNbrCols - iColStrt          
iCol = iColStrt                         
    
   Do While parseStart < Len(stuffToPaste)
    
  Sess0.Screen.PutString Mid(stuffToPaste, parseStart, parseLen), iRow, iCol
      parseStart = parseStart + parseLen
      parseLen = iNbrCols - iColNxt                          
      iCol = iColNxt                                          
      iRow = iRow + 1                                     
    Loop
    
    Sess0.Screen.MoveTo iRow, iCol

My challenge now is to figure out where to place the

CODE

InStr(70, stuffToPaste, " ")
to keep the words from cutting in half when wrapping.  
 

RE: Wrap Pasted Text In Attacmate


Quote:

to keep the words from cutting in half when wrapping.
In VB, there is a Split() function that parses a string based on a given delimiter.  In this case, the delimiter would be SPACE and given SPACE as the delimiter, Split() would parse the sting into individual WORDS.  So you could test the length of the string that is being placed on the screen, based on each individual word being concatenated to the string.

Unfortunately, EB does not have the Split() function, so you have to write your own, like...

CODE

Function SplitIt(s As String, d As String) As Variant
    Dim a() As String, idx As Integer
    Dim i As Integer, p1 As Integer, p2 As Integer
    
    p1 = 1
    For i = 1 To Len(s)
        If Mid(s, i, 1) = d Then
            GoSub ArrayMaint
        End If
    Next
    GoSub ArrayMaint
    
    SplitIt = a
    
    Exit Function
ArrayMaint:
    ReDim Preserve a(idx)
    p2 = i - p1
    a(idx) = Mid(s, p1, p2)
    p1 = p2 + p1 + 1
    idx = idx + 1
    Return
End Function

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
So Instr() wouldn't work for this?

RE: Wrap Pasted Text In Attacmate



Works.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
Will it work in my current code?  I have tried placing it multiple places. I guess I just don't understand the processing behind it all.

RE: Wrap Pasted Text In Attacmate



SplitIt() returns an ARRAY, that you need to process in your code.  I'd use it up front, before the Do...Loop, to parse the 'pasted' string, and then use the array result in the loop.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
I meant the InStr().  Will it work in my current code to accomplishe the same thing?  I have tried but to no avail.
I really do appreciate your help and patience with me! :)

RE: Wrap Pasted Text In Attacmate



Please do not just say, "I have tried but to no avail."  

If you want help, you need to provide clear, concise and complete information, which would include WHAT you tried, including code and WHAT the exact results were, including error messages and values.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
My appologies.  I don't understand vb enough to explain what it's doing.  I appreciate the help and patience, but I have taken on something that is above my head.  Thank you again for the help Skip.

RE: Wrap Pasted Text In Attacmate



Do you understand what I posted previous to you last post?

INFORMATION not meaningless hand wringing.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
yes I understand.

Quote (DizzyP):

Again, thank you!!! I was able to get it to work with that logic.  I was able to tweak it to make it start on the cursor so if the macro is run more than once it doesn't replace the previous.


CODE

iColStrt = Sess0.Screen.Col          
iRow = Sess0.Screen.Row              
iNbrCols = 75                    
iColNxt = iColStrt + 1              

parseStart = 1                          
parseLen = iNbrCols - iColStrt          
iCol = iColStrt                         
    
   Do While parseStart < Len(stuffToPaste)
    
  Sess0.Screen.PutString Mid(stuffToPaste, parseStart, parseLen), iRow, iCol
      parseStart = parseStart + parseLen
      parseLen = iNbrCols - iColNxt                          
      iCol = iColNxt                                          
      iRow = iRow + 1                                     
    Loop
    
    Sess0.Screen.MoveTo iRow, iCol
My challenge now is to figure out where to place the

CODE

InStr(70, stuffToPaste, " ")
to keep the words from cutting in half when wrapping.  

I've placed the InStr in multiple places.  What I remember doing is making parseStart = InStr(70, stuffToPaste, " ") and that leaves me with an "invalid function".

I would like to use Instr() if it will work for this because I'm not comfortable with arrays.  That is why I was asking if it will work to accomplish the same result as Split().

RE: Wrap Pasted Text In Attacmate



InStr() ONLY tells you where a string is in a string.

You must use the MID() function to pick apart the string.  You can look at my SplitIt() function to see how I did that.

FYI, when you refer to some piece of code, then post that piece of code. It is not sufficient to make an implicit reference to something posted earlier that very well could have been changed.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
I see your split function, but I don't understand it.  I don't get what the variables are and what they are doing.  Will this just work if I call it with the code I have and leave it (the function) as is?

RE: Wrap Pasted Text In Attacmate



Tell me what you do not understand.

SplitIt() returns an ARRAY.  Here's an example:

CODE

    Dim x, ind As Integer

    x = SplitIt("Now is the time!", " ")

    For ind = 0 To UBound(x)
        Debug.Print x(ind)
    Next
 

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
Found a setting for it in attachmate...no need for the macro.  I overlooked it before.  Thank you though.  I have learned a lot from this experience!!!

RE: Wrap Pasted Text In Attacmate



Please share your solution with other members.

Tek-Tips is not a one way street.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Wrap Pasted Text In Attacmate

(OP)
Paste options - row oriented.  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close