[Solved] Spin button event listener
[Solved] Spin button event listener
Hello,
I'm trying to make a spin button not only increment an associated cell, but also update another cell to a predetermined value.
I've associated an OpenOffice Basic macro with the event 'after updating', but I haven't been able to get this to work. Running the macro on its own works fine, but it's not being registered as a listener.
Assuming this can work, I was also wondering if it would be possible to determine whether the up or down arrow was pressed, but I can't find any documentation on the specific Event object.
Any ideas?
Thanks
I'm trying to make a spin button not only increment an associated cell, but also update another cell to a predetermined value.
I've associated an OpenOffice Basic macro with the event 'after updating', but I haven't been able to get this to work. Running the macro on its own works fine, but it's not being registered as a listener.
Assuming this can work, I was also wondering if it would be possible to determine whether the up or down arrow was pressed, but I can't find any documentation on the specific Event object.
Any ideas?
Thanks
Last edited by Hagar Delest on Sat Feb 19, 2022 12:29 pm, edited 1 time in total.
Reason: Tagged [Solved].
Reason: Tagged [Solved].
OpenOffice 4.1.5 on Windows 10
Re: Spin button event listener
I've managed to get the listener to work with the 'mouse release' event, but I'm still trying to figure out how to get more information about the event itself to guide the logic within the macro.
OpenOffice 4.1.5 on Windows 10
Re: Spin button event listener
https://www.openoffice.org/api/docs/com ... Event.html
Edit: if its not that mouse events struct, and if it is as well, you should be using MRI which will give you all the information.
https://extensions.openoffice.org/en/pr ... ction-tool
Code: Select all
sub eventname(ev)
'ev.buttons etc
end sub
https://extensions.openoffice.org/en/pr ... ction-tool
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Spin button event listener
Yeah I don't think the first one will have information about the spin button pressed, but I'm not sure.
But the MRI link looks promising--thanks!
But the MRI link looks promising--thanks!
OpenOffice 4.1.5 on Windows 10
Re: Spin button event listener
Its the same struct. Mri gives me this:
One way to find whether the up or down was clicked would be this:
(Name) (Value Type) (Value) (AccessMode)
Buttons short 1
ClickCount long 1
Modifiers short 0
PopupTrigger boolean False
Source .uno.XInterface -INTERFACE-
X long 21
Y long 33
Code: Select all
if ev.y > ev.source.getpossize.height\2 then
'its the lower one
end if
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Spin button event listener
a better way might be:
Edit: removed the msgbox line - can be hard to stop those keep popping up.
Code: Select all
global vv
Sub mousedown(ev)
vv= ev.source.value
End Sub
Sub whileadjusting(ev)
'top of spin pressed vv - ev.value = -1 else =1
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Spin button event listener
Awesome, that worked beautifully, thanks very much
OpenOffice 4.1.5 on Windows 10
Re: [Solved] Spin button event listener
You know what, this doesn't seem to work as well as I thought. It seems like there's some kind of internal counter to each spin button, and the math is being performed on these, so that when you switch to another button, if the first was incremented twice, incrementing the second button somehow produces a net -1, rather than a +1 for itself, or with decrementing a net +1 instead of a -1. Is there any way around this?
Actually it seems more complicated than that. I'm still trying to figure out what the pattern is.
Actually it seems more complicated than that. I'm still trying to figure out what the pattern is.
OpenOffice 4.1.5 on Windows 10
Re: [Solved] Spin button event listener
Please upload your ODF type sample file together with the embedded macro code.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: [Solved] Spin button event listener
Sure thing, here's a file that replicates the behaviour. I think the macros should be there, but if they aren't, please let me know and I'll try to reupload.
- Attachments
-
- test.ods
- (10.85 KiB) Downloaded 132 times
OpenOffice 4.1.5 on Windows 10
Re: [Solved] Spin button event listener
It looks like it might be that the delta measured spans the two inputs when switching.
Okay so I've moved the mouse listener from 'mouse button released' to 'mouse button pressed' and it seems to have resolved the issue. I realized that if the delta is spanning the inputs, then the mouse event must happen after the 'while updating' one, and logically pressed must come before it. If there's a better way to do it, that's great, but at least this seems to work. Thanks for all the help, in any case.
Okay so I've moved the mouse listener from 'mouse button released' to 'mouse button pressed' and it seems to have resolved the issue. I realized that if the delta is spanning the inputs, then the mouse event must happen after the 'while updating' one, and logically pressed must come before it. If there's a better way to do it, that's great, but at least this seems to work. Thanks for all the help, in any case.
OpenOffice 4.1.5 on Windows 10
Re: [Solved] Spin button event listener
Yeah sorry, I should have explicitly said the mousedown sub is for the mouse press not the mouse up.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Solved] Spin button event listener
Oh I'm sure it was partly my fault, as I already had mouse up in mind. Anyway, thanks for the help!
OpenOffice 4.1.5 on Windows 10