07-12-2022 02:48 PM - edited 07-12-2022 02:50 PM
Here's one possibility. It will even do the AM/PM conversion for you.
(If you want, you can leave out the ":" in the format. would make no difference)
07-12-2022 02:48 PM
That what was an example of the flow of logic lol. It's not the actual code I'm using
07-12-2022 03:38 PM - edited 07-12-2022 03:39 PM
Alrightyyyyyyy I think I'm just gonna use this that I whipped up real quick. Probably not the best, but it'll do. Like I said, I don't have any timestamps to begin with, just strings.
This is just to get military time values, then I can use range
07-12-2022 03:43 PM
07-12-2022 04:31 PM
No, that's still way too convoluted and overly complicated. What if the user enter "am" instead of "AM"? (hint: it would be considered PM!) What if the user enters 55 AM? What if he enter 5 XM?
The two pseudo-numeric fields should be numeric with correct input range limits and the AM/PM could be an enum or ring.
Did you even look at my earlier suggestion?
07-12-2022 04:33 PM
Yes I did, and it appeared as though your solution needed the timestamp data type, which I don't have unless I make one myself.
Also, again, these code snippets I'm posting are just examples for how the solution could work. In my actual code, all the hours, minutes, and AM/PM's are enums.
07-12-2022 05:47 PM - edited 07-12-2022 05:57 PM
Some fun with Scan From String and Format Into String can do the 12 to 24 hour conversion for you.
07-13-2022 10:40 AM
That's awesome, thank you!
07-13-2022 11:03 AM - edited 07-13-2022 11:53 AM
@crossrulz wrote:
Some fun with Scan From String and Format Into String can do the 12 to 24 hour conversion for you.
The problem is still that the inputs are strings and thus cannot be easily validated for correctness. Users can type the combined works of Shakespeare in there and the result would be garbage. 😄
As I said, I would use a combination of numeric and ring inputs, where the input range is correctly defined in the control(1..12, 0..59, AM=0, PM=12).
Here's how that could look like. (I added some optional code to validate the conversion. Of course I have not tested every possible input, so test for yourself 🙂 ).