Anybody have a good program for calculating the elapsed time between two times? As an example, in HHMMSS format,
090000
to
163200
is
7h32m
My particular use case is on a DM42, so any HP42 program should work fine, but I can't seem to find one out there. My intent is to take the program and integrate the sum feature, so I can add the resultant elapsed times to those registers and use the stats features on them.
Does it have the HMS- function like the 41cx (and probably the Time module too)?
As Garth and Peet mentioned, no programming necessary. The HP-42S/DM42/Free42 does have the HMS+ and HMS- functions. They use the HH.MMSSss format for time entry. Use FIX 4 (for HH.MM.SS) of FIX 6 (for HH.MM.SSss) display format for best results.
For your example type :
16.3200 [ENTER] 9.0000 [HMS-]
The answer is 7.3200 (with the display set to FIX 4).
You might want to assign the HMS+ and HMS- functions to the Custom menu if you use them frequently.
As others have mentioned, the HMS- function is already there, but keep in mind it will return results that are also in HH.MMSS format (meaning you can't sum those directly). You'll need to use the →HR function to convert from HH.MMSS to decimal hours, then you can sum up those results.
Thanks all, this is exactly what I needed! I'll whip up a quick program around this function and be set!
Ok, so now I started with the following, which I'll loop later:
Code:
00 { 52-Byte Prgm }
01▸LBL "TMSHT"
02 INPUT "DAY END"
03 INPUT "DAY START"
04 RCL "DAY END"
05 RCL "DAY START"
06 HMS-
07 →HR
08 Σ+
09 END
But I get a "Nonexistent" from Free42. This is literally my second program in a 42s ever... any debug ideas?
Your program works fine when I copied and pasted it into
Free42.
However it shortened the 2nd variable "DAY START" to "DAY STA":
Code:
00 { 48-Byte Prgm }
01▸LBL "TMSHT"
02 INPUT "DAY END"
03 INPUT "DAY STA"
04 RCL "DAY END"
05 RCL "DAY STA"
06 HMS-
07 →HR
08 Σ+
09 END
You get a "Nonexistent" message if the variable isn't created yet but the program wants to access it.
This might happen for instance if the program starts at line 04.
In such a case you can single step through the program with the SST or just the ▼ key.
While you press down the key the current line is displayed:
Code:
03 INPUT "DAY STA"
04▶RCL "DAY END"
HTH
(05-17-2022 11:56 PM)syzygetic Wrote: [ -> ]Ok, so now I started with the following, which I'll loop later:
Code:
00 { 52-Byte Prgm }
01▸LBL "TMSHT"
02 INPUT "DAY END"
03 INPUT "DAY START"
04 RCL "DAY END"
05 RCL "DAY START"
06 HMS-
07 →HR
08 Σ+
09 END
But I get a "Nonexistent" from Free42. This is literally my second program in a 42s ever... any debug ideas?
Your program seems to work as-is for me in Free42. I copied and pasted it into both mobile and desktop versions of Free42 and it works fine.
Interesting, thanks guys! This is my first time using winFree42 so maybe I have some setting messed up. I'll load it up on the real thing tomorrow and develop a bit more.
(05-18-2022 01:27 AM)Thomas Klemm Wrote: [ -> ]However it shortened the 2nd variable "DAY START" to "DAY STA":
on the 42s a variable name can have one to seven characters
Indeed, it was the variable length, thanks. I shortened it up and Free42 and the DM42 both like this now. On to looping!
Code:
00 { 40-Byte Prgm }
01▸LBL "TMSHT"
02 INPUT "DEND"
03 INPUT "DSTART"
04 RCL "DEND"
05 RCL "DSTART"
06 HMS-
07 →HR
08 Σ+
09 END
Thanks all, great forum here!
Glad, we could help.
(05-17-2022 11:56 PM)syzygetic Wrote: [ -> ]This is literally my second program in a 42s ever...
This is amazing. I started programming on an
HP-41CV as a teenager in the 80's.
All I had was curiosity, excellent manuals, and plenty of time.
I can hardly imagine what that would be like for me today.
However, I wish you a lot of fun on your journey.
It piqued my interest as to what might have caused the problem.
So, I encoded your program with the
DM42 Programming tool.
And lo and behold, it doesn't shorten the name of the variable.
I downloaded the
.raw file into
Free42 and ran your program and got the same error message:
Nonexistent
It seems that the
INPUT "DAY START" command creates a variable with a corrupted name.
These are the two variables, if they are used in a program:
Code:
00 { 20-Byte Prgm }
01 RCL "DAY END"
02 RCL "DAY STA├├"
03 END
No wonder that this can't be found.
(05-18-2022 08:35 PM)Thomas Klemm Wrote: [ -> ]This is amazing. I started programming on an HP-41CV as a teenager in the 80's.
All I had was curiosity, excellent manuals, and plenty of time.
I can hardly imagine what that would be like for me today.
I have to say, the manuals are indeed excellent. I have a lot of experience with other languages, just nothing in RPN/RPL, and really nothing stack based, such as FORTH. It's refreshingly simple, though, even if it's a lot more encumbered here because of the need to compile, them import to an emulator or calculator. I do wish there were a command line utility I could use for development work, just to reduce the turnaround time on debugging like this.
(05-19-2022 02:21 PM)syzygetic Wrote: [ -> ]I do wish there were a command line utility I could use for development work, just to reduce the turnaround time on debugging like this.
There's an extension for VS Code you might consider:
(12-19-2018 04:48 PM)Heilingbrunner Wrote: [ -> ]More details see Visual Studio Code Marketplace - HP42S-free42.
This linked thread might be of interest as well:
Txt to Raw and Raw to Txt