|
View:
New views
11 Messages
—
Rating Filter:
Alert me
|
|
|
Avoiding Moving The Cursor Before Start of DocumentI 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: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Avoiding Moving The Cursor Before Start of DocumentHi Hal,
Hal Vaughan wrote (26-6-2009 8:41) > [...] > 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? > [...] What I would try (I don't have a working example at hand, sorry) is creating a textcursor at the start of the text, and compare the range of your oCurs with that range. HTH, Cor -- Cor Nouws - nl.OpenOffice.org marketing contact Ontwikkelaar? Join! http://council.openoffice.org/developers.html Gevoel niet vrij te zijn? Zie www.nieuwsteversie.nl --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Avoiding Moving The Cursor Before Start of DocumentHal,
you have getposition and jumptostartofpage to compare the 2 positions hope it helps Fernand 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: dev-unsubscribe@... > For additional commands, e-mail: dev-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Avoiding Moving The Cursor Before Start of Documentwhen len(sChar) = 0 then you get the error
> Hal, > > you have getposition and jumptostartofpage to compare the 2 positions > > hope it helps > > Fernand > > > 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: dev-unsubscribe@... >> For additional commands, e-mail: dev-help@... > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@... > For additional commands, e-mail: dev-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Avoiding Moving The Cursor Before Start of DocumentOn Jun 26, 2009, at 5:28 AM, Cor Nouws wrote: > Hi Hal, > > Hal Vaughan wrote (26-6-2009 8:41) >> [...] >> 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? >> [...] > > What I would try (I don't have a working example at hand, sorry) is > creating a textcursor at the start of the text, and compare the > range of your oCurs with that range. Hmmm.... I'd have to extend the text cursor at the start of the text one character forward each time I move the other one character back, so I could match it. I have to think it over because I need to be sure I don't just compare the two but am also sure the key phrase I'm looking at is complete. I'm not sure, but I think I can imagine the two phrases matching even if it's not the one at the start. I don't know if that makes a difference, though. Hal --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Avoiding Moving The Cursor Before Start of DocumentOn Jun 26, 2009, at 7:45 AM, Fernand Vanrie wrote: > when len(sChar) = 0 then you get the error I had been checking for what sChar is, but kept forgetting to check for it's length. Thanks. I also realized I had made another goof. I intended to limit the length of key phrases to 32 characters. While I checked for the length, I forgot to keep increasing the length of the text I'm comparing! Hal >> Hal, >> >> you have getposition and jumptostartofpage to compare the 2 positions >> >> hope it helps >> >> Fernand >> >> >> 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: dev-unsubscribe@... >>> For additional commands, e-mail: dev-help@... >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscribe@... >> For additional commands, e-mail: dev-help@... > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@... > For additional commands, e-mail: dev-help@... > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Avoiding Moving The Cursor Before Start of DocumentI 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: dev-unsubscribe@... > For additional commands, e-mail: dev-help@... > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Avoiding Moving The Cursor Before Start of DocumentHi Hal,
Thnks for posting back. Your proposed solution looks OK. When you have the final version, I'll try to take a closer look. Maybe you can post it as extension on the extension site? Regards - Cor Hal Vaughan wrote (26-6-2009 17:19) > 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. -- Cor Nouws - nl.OpenOffice.org marketing contact Ontwikkelaar? Join! http://council.openoffice.org/developers.html Gevoel niet vrij te zijn? Zie www.nieuwsteversie.nl --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Avoiding Moving The Cursor Before Start of DocumentHi Hal,
Message de Hal Vaughan date 2009-06-26 08:41 : > 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. Methods goLeft and goRight return a boolean True if the move could be done, False if it failed. if oCurs.goLeft(1, True) then ' do your job else ' already at start of text end Regards Bernard --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Avoiding Moving The Cursor Before Start of DocumentOn Jun 27, 2009, at 3:51 AM, Cor Nouws wrote: > Hi Hal, > > Thnks for posting back. > Your proposed solution looks OK. When you have the final version, > I'll try to take a closer look. Maybe you can post it as extension > on the extension site? I still have to find the site and look up how to post it. I was looking over what I had done and thought I had published this for others, but, perhaps with that one bug, I hadn't done that. I also like to do a write-up and put anything like that on my blog when I do it. The code is below. It's working now. I also noticed a LONG delay from when I submit my emails to this list and when they show up. I'll have to see if I've changed my email address since I joined or something like that. I left in the comment where the bug was. It's not there now. Of course, since I've gotten it working, I get a good point from someone else where I could have just checked the result of goLeft(). I may re- write it, but that breaks a person coding rule of mine: If it ain't broke, don't fix it. (I've spend WAY too much of my life in front of a CRT writing code!) Hal > > Regards - Cor > > Hal Vaughan wrote (26-6-2009 17:19) >> 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. Sub InsertAutoMacroText oDoc = ThisComponent oCurs = oDoc.getCurrentController().getViewCursor() iEnd = false iCount = 0 Do oCurs.goLeft(1, true) sKey = oCurs.getString() If iCount = Len(sKey) Then iEnd = true iCount = 0 Else sChar = Left(sKey, 1) ' MsgBox "String: " + sKey + ", Char: " + sChar '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 iCount = Len(sKey) If iChar < 33 Then iEnd = true If iCount > 32 Then iEnd = true End If Loop Until iEnd If iCount > 0 Then oCurs.goRight(1, true) sKey = oCurs.getString() ' sText = "Replaced ->" + sKey + "<-" sText = GetDocumentVariable(sKey) oCurs.setString(sText) oCurs.collapseToEnd() End Sub --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: Avoiding Moving The Cursor Before Start of DocumentOn Jun 27, 2009, at 5:12 AM, Bernard Marcelly wrote: > Hi Hal, > Message de Hal Vaughan date 2009-06-26 08:41 : >> 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. > > Methods goLeft and goRight return a boolean True if the move could > be done, False if it failed. > > if oCurs.goLeft(1, True) then > ' do your job > else > ' already at start of text > end Thanks! I see that now, but I've got the code in to check the length -- there was a delay in my emails going through, so we have a lag time here. I have it working with a length check for now. I may switch to this, since it's more concise, but I generally avoid re-writing whenever I can. I wish I had seen this before I wrote my patch! Hal --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
| Free embeddable forum powered by Nabble | Forum Help |