| View previous topic :: View next topic |
| Author |
Message |
Robby OOo Advocate


Joined: 21 Sep 2004 Posts: 263 Location: The Netherlands
|
Posted: Sun Oct 17, 2004 2:28 am Post subject: How to move the cursor to the beginning of the row? (in Calc |
|
|
Does anybody know?
(I mean select the first cel of the current row)
Robby
Last edited by Robby on Sat Oct 30, 2004 11:05 pm; edited 1 time in total |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Sun Oct 17, 2004 6:44 pm Post subject: |
|
|
The question here that I ask myself is, what is the current row for you?
Does it mean one of the cells of this row is selected or does it mean the last row whose cells contain values, formulas or strings (=contents)?
Christian _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
uros Super User


Joined: 22 May 2003 Posts: 601 Location: Slovenia
|
Posted: Sun Oct 17, 2004 10:52 pm Post subject: |
|
|
Hi Robby!
Try this:
| Code: | Sub FirstCellInActiveRow
oDesktop = createUnoService("com.sun.star.frame.Desktop")
oDocument = ThisComponent
oActiveCell = oDocument.CurrentSelection.RangeAddress
oSheet = oDocument.Sheets.getByIndex(oActiveCell.Sheet)
nRow = oActiveCell.StartRow
oDocument.CurrentController.Select(oSheet.getCellByPosition(0,nRow))
End Sub
|
Uros |
|
| Back to top |
|
 |
Robby OOo Advocate


Joined: 21 Sep 2004 Posts: 263 Location: The Netherlands
|
Posted: Mon Oct 18, 2004 1:39 am Post subject: |
|
|
Hi Cybb20,
I want to make a function that clears the contents of the cells in colom D en E of the current row, fill in a "1" in colom D and then go one row down. This function a want to link to F1. So the current row changes every time.
I was planning to send the cursor back to colom A and than move the cursor a few steps to the right untill D is reached. Perhabs not the most efficient way to do it?
Hi Uros,
Thanks for the code! I'm going to try it and will let you know if it works!
Robby |
|
| Back to top |
|
 |
Robby OOo Advocate


Joined: 21 Sep 2004 Posts: 263 Location: The Netherlands
|
Posted: Mon Oct 18, 2004 3:35 am Post subject: |
|
|
Last edited by Robby on Sat Oct 23, 2004 6:19 am; edited 1 time in total |
|
| Back to top |
|
 |
Robby OOo Advocate


Joined: 21 Sep 2004 Posts: 263 Location: The Netherlands
|
Posted: Mon Oct 18, 2004 7:20 am Post subject: |
|
|
Hi Uros,
The code you provided is even more convenient than my clumsy way. I can access directly the right row, no need to go to the first row first. If i select a cell in the right row with your code than i don't see a box around the selected cell. (The box that shows that you have selected the cell)
Further more i see that it isn't possible to declaire the function i am making to the functionkeys F1 and F2 because these are "gray". Is there a way around this. I realy want to use F1 and F2.
Robby
Last edited by Robby on Sat Oct 30, 2004 6:59 am; edited 1 time in total |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1572 Location: Frankfurt, Germany
|
Posted: Mon Oct 18, 2004 11:29 am Post subject: |
|
|
What you could do about F1 and F2 is register a keyhandler and surpress the Online Help and thereby setting a global boolean variable that is set to true when the user has pressed F1 and later you can handle it.
But that's not very clean I admit and maybe someone else might find something better.
So is the main question with Uros' code solved?
Christian _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
Robby OOo Advocate


Joined: 21 Sep 2004 Posts: 263 Location: The Netherlands
|
Posted: Mon Oct 18, 2004 10:57 pm Post subject: |
|
|
Hi Chistian
Yes Uros' code works greath, better than i hoped for! (just missing the border as i stated).
Will your suggestion have implications for other calc documents also? (Because it's only mend for this specific document i'm working on). I will have to do some homework before i understand what you suggest with the keyhandler because i have never done something like that before. So i have to come back to you on that. I'm going to study the manuals again. Unless there are better solutions of course....
Thanks for the suggestion.
Robby |
|
| Back to top |
|
 |
Robby OOo Advocate


Joined: 21 Sep 2004 Posts: 263 Location: The Netherlands
|
Posted: Sat Oct 23, 2004 6:17 am Post subject: |
|
|
Hi all !
I've made the macro i wanted. I don't know how to move the cursor selecton by relative position so i did it this way. I think it's perhaps not the most efficiënt way to do it, but it works.
I see that if i link f.i. F2 to Sub yes than it is for all Calc documents. This is not what i want. So i'm going to look into the keyhandler suggestion of you Christian. Any suggestions where i can find info on this subject?
Thanks Robby
Sub yes
If ThisComponent.CurrentController.ActiveSheet.Name <> "Vragen" then
ThisComponent.CurrentController.setActiveSheet(ThisComponent.Sheets.getByName("Vragen")) 'Activate sheet "Vragen"
End if
oDesktop = createUnoService("com.sun.star.frame.Desktop")
oActiveCell =ThisComponent.CurrentSelection.RangeAddress
oSheet = ThisComponent.Sheets.getByIndex(oActiveCell.Sheet)
nRow = oActiveCell.StartRow
Thiscomponent.CurrentController.Select(oSheet.getCellByPosition(4,nRow))
ThisComponent.CurrentController.getSelection().Value = 1
Thiscomponent.CurrentController.Select(oSheet.getCellByPOsition(5,nRow))
ThisComponent.CurrentController.getSelection().clearContents(com.sun.star.sheet.CellFlags.VALUE)
ThisComponent.CurrentController.Select((oSheet.getCellByPosition(4,nRow+1))
End Sub
Last edited by Robby on Sat Oct 30, 2004 7:00 am; edited 1 time in total |
|
| Back to top |
|
 |
uros Super User


Joined: 22 May 2003 Posts: 601 Location: Slovenia
|
Posted: Wed Oct 27, 2004 5:25 am Post subject: |
|
|
Hi Robby!
I've being away for some days and out of discussion. I'm sure your macro works fine, I just want to add some little advice.
You don't have to activate cell to change its value or to clear it. Do so at the end only, to activate a cell in next row.
| Code: |
Sub FirstCellInActiveRow
oDesktop = createUnoService("com.sun.star.frame.Desktop")
oDocument = ThisComponent
oActiveCell = oDocument.CurrentSelection.RangeAddress
oSheet = oDocument.Sheets.getByIndex(oActiveCell.Sheet)
nRow = oActiveCell.StartRow
oSheet.getCellByPosition(3,nRow).Value = 1 ' column D
oSheet.getCellByPosition(4,nRow).clearContents(1) ' column E
oDocument.CurrentController.Select(oSheet.getCellByPosition(3,nRow+1))
End Sub |
| Quote: | | .clearContents(com.sun.star.sheet.CellFlags.VALUE) |
Constant numeric values could be used instead of flags:
1 - value
2 - date, time
4 - strings
8 - annotation
16 - formula
32 - hardattr
64 - styles
128 - objects
This numeric values could be added and only their sum used in function, i.e. 21 clears value, string an formula.
Hope this helps to you and someone else.
Uros |
|
| Back to top |
|
 |
Robby OOo Advocate


Joined: 21 Sep 2004 Posts: 263 Location: The Netherlands
|
Posted: Sat Oct 30, 2004 12:19 am Post subject: |
|
|
Hi Uros,
Your suggestion works very good! Thanks. I've replaced all codelines in my programe with it. I'm not sure why you enter the code : "oDesktop = createUnoService....."
It seems to have no function, because oDesktop is never called for in the rest of the code.
Do you have any suggestions regarding keyhandlers?
Robby |
|
| Back to top |
|
 |
Robby OOo Advocate


Joined: 21 Sep 2004 Posts: 263 Location: The Netherlands
|
Posted: Sat Oct 30, 2004 10:40 am Post subject: |
|
|
I'm trying to use the example in the macro op Andrew Pitonyak as a start
The goal is to start different macro's by pressing the next keys:
F1 -> macro1
F2 -> macro2
alt z -> macro4
alt x -> macro5
These keys should only be active in the current document.
Andrew's code (in black i tried to acces the functionkeys, but this doesn't work):
Option Explicit
Global oDocView
Global oKeyHandler
Sub RegisterKeyHandler
oDocView = ThisComponent.getCurrentController
oKeyHandler = createUnoListener("MyApp_", "com.sun.star.awt.XKeyHandler")
' writedbginfo oKeyHandler
oDocView.addKeyHandler(oKeyHandler)
End Sub
Sub UnregisterKeyHandler
oDocView.removeKeyHandler(oKeyHandler)
End Sub
Sub MyApp_disposing(oEvt)
'nothing to do here
End Sub
Function MyApp_KeyPressed(oEvt) As Boolean
select case oEvt.KeyChar
case "z", "x", "c", "v", "{F1}", "[F2]", "F3", "<F4>", "#F5"
MyApp_KeyPressed = True
msgbox "key """ & oEvt.KeyChar & """ not allowed!"
case else
MyApp_KeyPressed = False
end select
End Function
Function MyApp_KeyReleased(oEvt) As Boolean
MyApp_KeyReleased = False
End Function |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3152 Location: Columbus, Ohio, USA
|
Posted: Sat Oct 30, 2004 5:00 pm Post subject: |
|
|
Is there a reason that you want to write a key handler rather than simply assigning the keys as hot keys to start a macro? Wait, I know, it is because you can not use F1 and F2.... Hmmmm.... It also looks like you can not specify ALT+z or ALT+x from the configuration portion....
Well, just for you, I am adding another small little section that reads something like this:
| Quote: | | The question came up, how can I intercept F1 or Alt+z. The KeyChar for the function keys have an ascii value of zero. Check the KeyCode for special characters. Although I do not see it mentioned elsewhere, you should also check the MODIFIERS property to make certain that the control, alt, and shift keys are NOT used. In the followin example, I compare directly to the MOD2 key modifier even though this is only a flag. I only want to trap Alt+z, not Ctrl+Alt+z or any other variant. This can be a problem, however. I do not really care about the state of the shift keys. If the caps lock is pressed, then shift+z returns “z” rather than “Z”. It is probably safer to check for character, MOD2 and NOT MOD1. |
| Code: | If oEvt.KeyCode = com.sun.star.awt.Key.F1 AND oEvt.MODIFIERS = 0 Then
MsgBox "Ha ha, I will NOT allow you to use F1 today!"
MyApp_KeyPressed = True
Exit Function
End If
If oEvt.KeyChar = "z" AND oEvt.MODIFIERS = com.sun.star.awt.KeyModifier.MOD2 Then
MsgBox "Ha ha, I will NOT allow you to use Alt+z today!"
MyApp_KeyPressed = True
Exit Function
End If |
_________________ --
Andrew Pitonyak
My Document: http://www.pitonyak.org/AndrewMacro.odt
Free Info: http://www.pitonyak.org/oo.php
Most hated bug: http://www.openoffice.org/issues/show_bug.cgi?id=84159 |
|
| Back to top |
|
 |
Robby OOo Advocate


Joined: 21 Sep 2004 Posts: 263 Location: The Netherlands
|
Posted: Sun Oct 31, 2004 12:26 am Post subject: |
|
|
Hi Andrew,
I want to use the F1 function and I couldn't assign it. But an other reason was that you can't assign it only for the current document; it will be assigned for all documents.Your code solves this; thank you for it. I googled all over the internet and couldn't find a thing. Well now you're at it... I'm curious how to specify a <ctrl> + z key....
Some strange things....
- I assinged the F1, F2, F3 and F4 keys to four differend macro's that enter the value '1' in a cell (Thanks to the code of Uros!). Now i added the keyhandler and all cells are blocked for input from the keyboard
- When the keyhandler is created for a second time it will run the imputmacro's twice. Is it possible to check first if the keyhandler is already created and running, before creating it again?
Thanks! Robby |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3152 Location: Columbus, Ohio, USA
|
Posted: Sun Oct 31, 2004 2:44 pm Post subject: |
|
|
I have tried this code to obtain Alt+z. Notice that this ONLY notices the lower case z.
| Code: | If oEvt.KeyChar = "z" AND _
((oEvt.MODIFIERS AND com.sun.star.awt.KeyModifier.MOD2) <> 0) AND _
((oEvt.MODIFIERS AND com.sun.star.awt.KeyModifier.MOD1) = 0) Then
MsgBox "Ha ha, I will NOT allow you to use Alt+z today!"
MyApp_KeyPressed = True
Exit Function
End If |
I have NOT tried this code to obtain Ctrl+z. Notice that this ONLY notices the lower case z.
| Code: | If oEvt.KeyChar = "z" AND _
((oEvt.MODIFIERS AND com.sun.star.awt.KeyModifier.MOD2) = 0) AND _
((oEvt.MODIFIERS AND com.sun.star.awt.KeyModifier.MOD1) <> 0) Then
MsgBox "Ha ha, I will NOT allow you to use Alt+z today!"
MyApp_KeyPressed = True
Exit Function
End If |
_________________ --
Andrew Pitonyak
My Document: http://www.pitonyak.org/AndrewMacro.odt
Free Info: http://www.pitonyak.org/oo.php
Most hated bug: http://www.openoffice.org/issues/show_bug.cgi?id=84159 |
|
| Back to top |
|
 |
|