I've been working on a diary program (ChronoLog). but lately my date and time variable keeps resetting. I've spent hours trying to fix it. I'm wondering if there's a known issue.
Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
October 11, 2022 DateTime resetting | ||||
---|---|---|---|---|
| ||||
October 11, 2022 Re: DateTime resetting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel | On Tuesday, 11 October 2022 at 22:09:34 UTC, Joel wrote: >I've been working on a diary program (ChronoLog). but lately my date and time variable keeps resetting. I've spent hours trying to fix it. I'm wondering if there's a known issue. An ordinary DateTime variable? Those are pretty simple and won't reset unless something else is wrong around it. Do you have the code online? Or can at least show some of the context around its use? |
October 11, 2022 Re: DateTime resetting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D Ruppe | On Tuesday, 11 October 2022 at 22:21:35 UTC, Adam D Ruppe wrote: >On Tuesday, 11 October 2022 at 22:09:34 UTC, Joel wrote: >I've been working on a diary program (ChronoLog). but lately my date and time variable keeps resetting. I've spent hours trying to fix it. I'm wondering if there's a known issue. An ordinary DateTime variable? Those are pretty simple and won't reset unless something else is wrong around it. Do you have the code online? Or can at least show some of the context around its use? I programmed the date and time stuff past midnight, then I think I had trouble onwards. Here's code, I've included other code (maybe it can be compiled and run): |
October 11, 2022 Re: DateTime resetting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel | I'm just eyeballing the code, is it the g_dateTimeCursor you're concerned about? That's the only one I really see there. A few things that might explain it:
I also see a _dateTime in there. This is a member of the Control struct.... and since it is a struct, remember it is an independent value whenever you use it, just like an int. int a = 5; int b = getA(); // but a is still 5 here! Because ints are values, when it is returned by the function, it gets an independent copy. Structs work the same way. So that So this might cause your problem too, with the info being lost. It is possible that changing getControl to return Let me know if this helps. |
October 11, 2022 Re: DateTime resetting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D Ruppe | On Tuesday, 11 October 2022 at 23:28:50 UTC, Adam D Ruppe wrote: >I'm just eyeballing the code, is it the g_dateTimeCursor you're concerned about? That's the only one I really see there. [...] Yes! :-D getControl was the issue, I've used ref on its return value now. Thanks so much for your help! :-) |