I may have a solution that's a bit different than what's been
suggested, but thanks to both Cor and Fernand because what they wrote
gave me the idea. I still have to code this and be sure it's what I
want. A quick check tells me that if I have one character at the
beginning, once I move the cursor over that character, I can keep
trying oCurse.goLeft(), but the length of the string in the selection
(sKey in this case) does not change. So I think I can just keep track
of the length of the selected string. If I try goLeft() and the
string length doesn't change, that should tell me I can't go left
anymore and I'm at the beginning.
If this works, I'll post a fixed version. I think I also exported
this or was going to so other people could use them as well. If I
haven't done it already, I will. I like it because it's a lot like
AutoCorrect, but I can define new key phrases and replacement texts in
a hurry and they are stored in the document, but can be exported to a
text file and imported in another document, so they are document
specific but can be transferred.
Hal
On Jun 26, 2009, at 2:41 AM, Hal Vaughan wrote:
I have a macro collection I've posted about before. It works like
the AutoCorrect function, but I've customized it for me. If I hit
Ctrl-Shift-T (actually Command-Shift-T since I'm now on an iMac), I
get a dialog that lets me define a key phrase and the AutoText that
goes with it. Then when I'm writing, after any space or at the
start of a new line, I hit Command-T. That activates a macro that
starts at the current cursor position and steps back until it finds
a space or a control character. The only problem with this is if I
do this at the start of a document I end up with a null character or
something instead and I can't do a comparison on it. So is there
some way, after moving the cursor, to check and see if I'm at the
start of the document?
The code that steps backwards through the characters in the document
is below. Notice that all I do is step back, check each new
character added to the start of the selection and see if the value
is that of a space or less. I want to add an If statement before I
move the cursor left so if I'm trying to move it past the start of
the document, I can catch it.
Of course, another alternative is to be able to define a variable to
whatever character I'd find at the start of the document and compare
sChar to that value to see if I'm at the start.
Sub InsertAutoMacroText
oDoc = ThisComponent
oCurs = oDoc.getCurrentController().getViewCursor()
iEnd = false
iCount = 0
Do
'Go back one character, then get that character and put it in a
separate variable
'for comparison.
oCurs.goLeft(1, true)
sKey = oCurs.getString()
sChar = Left(sKey, 1)
'BUG: This next line throws an error if we try to use this at the
start of a
'document.
iChar = Asc(sChar)
' MsgBox "String: " + sKey + ", Char: " + sChar + ", Char Code: " +
iChar
If iChar < 33 Then iEnd = true
If iCount > 32 Then iEnd = true
Loop Until iEnd
oCurs.goRight(1, true)
sKey = oCurs.getString()
' sText = "Replaced ->" + sKey + "<-"
sText = GetDocumentVariable(sKey)
oCurs.setString(sText)
oCurs.collapseToEnd()
End Sub
I've been going through the API, but I have a disadvantage: I
haven't been working with it much recently, so I don't seem to find
things as easily as I have in the past.
Any help on this is much appreciated!
Hal
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]