I do not have time to test this, so...

Hal Vaughan wrote:
I recorded a macro to select text, copy it to the keyboard, then to enter a new character. In the long run, I'm going to want a macro that selects the character before the cursor, then reads in that character so I can use it to compare to something else. When I'm done, I'd delete that character from the text, then enter in new text.

It'd work like autotext, but it'd also let me call another macro along the way, since there's a bug (as mentioned in another thread) in autotext that doesn't let you bind macros to it.

I'm using the code below to select the one character and copy it to the keyboard, then enter in another keypress. I've got a couple questions:

1) This all uses dispatch statements. I remember there were some issues with this previously, but that may have been with slot numbers or something like that. Am I safe writing my macro to dispatch commands, or will that get outdated? This will always be used from the keyboard, so there's no issue with the UI not being in use when I do this.

2) Once I've selected a character (or more text) or copied it to the clipboard, how can I read what that character is? I've looked at Andrew's Macro document, but I'm still putting all that info together and it uses objects, not the dispatcher. Is there a quick way, in Basic, to dump the selected text into a string?

Thanks for any help on this!
You do not say what you want to do if more than one thing is selected, but does this code make any sense to you?

Function GetFirstSelectedString(oDoc As Object) As String
 Dim oSels
Dim oSel Dim oCursor
 Dim i As Integer

 GetFirstSelectedString = ""
 If IsNull(oDoc) Then Exit Function
 oSels = oDoc.getCurrentSelection()
 If IsNull(oSels) Then Exit Function

 If oSels.getCount() = 0 Then Exit Function
 For i = 0 To oSels.getCount() - 1
   oSel = oSels.getByIndex(i)
   oCursor = oSel.getText().CreateTextCursorByRange(oSel)
   If Not oCursor.IsCollapsed() Then
     GetFirstSelectedString = oCursor.getString()
     Exit Function
   End If
 Next
End Function

A bit less safe, but shorter.

Function GetFirstSelectedString() As String
 Dim s$
Dim oSel Dim oSels Dim i As Integer

 GetFirstSelectedString = ""
 s = ""
 oSels = ThisComponent.getCurrentSelection()
 For i = 0 To oSels.getCount() - 1
   oSel = oSels.getByIndex(i)
   s = oSel.getString()
   If Len(s) > 0 Then
     GetFirstSelectedString = s
     Exit Function
   End If
 Next
End Function


--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to