Ask Your Question
0

Add shortcut to increment/decrement date by a day?

asked 2020-03-13 12:10:27 +0200

perlancar gravatar image

How would I start doing this? It would make entering financial transactions so much nicer.

I would also like to a shortcut to increment or decrement a number by say 1000 or 10.

As a side note, org-mode in Emacs has this shortcut C-c up/C-c down which you can apply to the year/month/day to increment or decrement date by that period.

edit retag flag offensive close merge delete

Comments

I cannot test with a Linux currently, and I don't know therefore if the modifiers used "extensively" by my proposed code are also working there. If you test the code, please report.
(Anyway I only tested successfully under Win with LibO V5.4 and 6.0+. A few older versions I tested with didn't support the "modifier event" sufficiently:)

Lupp gravatar imageLupp ( 2020-03-13 23:50:46 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-03-13 16:12:02 +0200

Lupp gravatar image

updated 2020-03-13 23:13:34 +0200

I don't think something of the kind is implemented. You will need user code (in your case custom code?) for the purpose.
Always concerned to make "financial transactions nicer" (for other people), and when feeling a little bit bored, I designed a usable solution.
It is contained in this attachment. Check the code for beeing clean (no malware) and reload it with permission for macro execution. The document comes with a special little toolbar with only one sensitive area labeled IncDec.
Together with the modifiers Shift/Ctrl/Alt it should be sufficiently flexible. The usage is explaind in the sheet.
Have a lot of fun.
If you decide to actually use the code in the long run you should
- move it to your local 'Standard' library,
- add the Sub for direct call to an appropriate toolbar,
- consider to donate to a foundation supporting a children's hospital (or something of the kind).

===Edit 2020-03-13 about 22:10 UTC===
On a long walk I got a hunch there might be an issue with the DateSerial function of Basic - and there was. It is unable (unwilling) to allow for carries caused by excess month or day ordinals. The comparable Calc function DATE handles carries as needed for the purpose, and I reworked the code to use DATE via a FunctionAccess object. In addition I decided to also implemet treatment for values formatted 'TimeOnly' (independent of whether or not they have a hidden date part). The logical (Boolean) format is now also handled - by simple negation.
I would suggest you use (if at all) the new version contained in this new attachment. I even consider to use the tool myself. A test is started.

edit flag offensive delete link more

Comments

@Lupp: Great! Would you possibly consider DateAdd? (I filed tdf#131332 regarding the help page :-))

And also consider making it an extension with some pre-configured keyboard shortcuts?

Mike Kaganski gravatar imageMike Kaganski ( 2020-03-14 08:20:33 +0200 )edit

Thanks for hinting me to the 'DateAdd' function. However, I tend to challenge rarely used Basic functions due to the fact that there may be some users NOT reporting bugs they tumbled over. At least @Mike Kaganski once told me so. Bugs reported but not fixed are also said to occur. To convince myself of the trustworthyness of a Basic function of the kind I would need extensive testing. Anyway I don't understand how to use the 'Add' strings "w" and "ww".
Concerning the extension case: I never did it. I would need help. I'm 75 and learning new things slowly. (There are also fields where I am making fast progress. In forgetting I'm a champion.)
"Great" answers deserve upvoting. ;-)

Lupp gravatar imageLupp ( 2020-03-14 11:32:37 +0200 )edit

However, I tend to challenge rarely used Basic functions due to the fact that there may be some users NOT reporting bugs they tumbled over

That's nice and encouraged; yet I cannot understand in what context was that said (i.e., which rarely used function you refer to; and if my proposal somehow conflicts with the said challenging).

(I'm looking at what those "of year" mean in the context of the function.)

Concerning the extension case: I never did it

... me too ;-) My friend did that when he prepared some extensions I helped to code.

"Great" answers deserve upvoting. ;-)

You are absolutely right! I must remind that myself more often.

Mike Kaganski gravatar imageMike Kaganski ( 2020-03-14 11:43:36 +0200 )edit

Anyway I don't understand how to use the 'Add' strings "w" and "ww"

The three options: "y", "w", and "d", appear to do exactly the same in SbRtl_DateAdd: they add 1 day to the passed date, without any other fancy processing. There are other functions that differentiate them: DateDiff and DatePart. The interval strings used in all these functions are unified.

Mike Kaganski gravatar imageMike Kaganski ( 2020-03-14 12:04:16 +0200 )edit

I suppose DateAdd to be "rarely used". I may be wrong.
The comment I (roughly) quoted you with from memory wasn't about Basic specifically. That wasn't very long ago, but I cannot find it now.
From memory again: IsNumeric("+1") = false, IsNumeric("-1") = true. Where - and with what justification - is this specified?
Besides missing specifications there are many doubtable ones. (I now the logic of this sentence is broken.) ODF (1.2 part 2, 1.3 part 4) worry (concerning the syntax of textual representation in the file described in RegfEx-enriched Backus notation) about numbers without an integer part - but don't allow for signs except by mentioning that " negative numbers are positive numbers with a prefix '-' ". As an exponent part "E+1" is accepted. Why?
ALGOL60 did it better! I can hardly cope with this way, and the few RFC I read didn't taste well. ...

Lupp gravatar imageLupp ( 2020-03-14 12:30:45 +0200 )edit

@Lupp: the IsNumeric question seems offtopic?

Besides, ODF is unrelated to StarBasic (which might not have any standard at all, I'm afraid)...

But I can say that e.g. Excel's VBA gives true for IsNumeric("+1")

So as you challenge those functions, I assume you also file the related bugs? ;-) I could only find tdf#123158 related to another problem with IsNumeric though.

Mike Kaganski gravatar imageMike Kaganski ( 2020-03-14 12:50:43 +0200 )edit

@Mike Kaganski: I knew tha was off topic - in a sense. It was an example for my resons to distrust Basic functions, and what you told in your comments above enforced my opinion insofar.
That ODF and StarBasic are unrelated also is clear to me. Under some aspects they may suffer from similar diseases. We had that already more than once. You understand ODF manners to specify things better thn I do, obviously.
Thanks for your patience!

Lupp gravatar imageLupp ( 2020-03-14 13:04:25 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-03-13 12:10:27 +0200

Seen: 84 times

Last updated: Mar 13