Reuse initial variables after a specific time

 

Hi friends,

does anybody know how to reuse the initial variables after a specific time?

suppose that you've given values to some variables at the start of the day as their initial value and by starting the program,it constantly changes these variable as time passes . and then you want to use the initial values for the new day which starts from 00:00.

I Would like to hear your helpful suggestions ;)

 
parham.trader:

Hi friends,

does anybody know how to reuse the initial variables after a specific time?

suppose that you've given values to some variables at the start of the day as their initial value and by starting the program,it constantly changes these variable as time passes . and then you want to use the initial values for the new day which starts from 00:00.

I Would like to hear your helpful suggestions ;)

Use a second variable to hold the initial value. Then at the start of the new day . .

variable = VariableInitialValue;

. . . done.

 

Or you can use an array with two elements to store the initial value and the value which will vary throughout the day (or whatever period).

int variable[2] = {10, 0};  // variable[0] is the initial starting value; variable[1] stores the value which changes throughout the period

When you want to reinitialize the variable to start-of-period state, just do:

variable[1] = variable[0];
 
Thirteen:

Or you can use an array with two elements to store the initial value and the value which will vary throughout the day (or whatever period).

When you want to reinitialize the variable to start-of-period state, just do:

Why not just use self documenting code ? variable[0] and variable[1] don't distinguish themselves from each other . . .
 
RaptorUK:
Why not just use self documenting code ? variable[0] and variable[1] don't distinguish themselves from each other . . .

For most people, inline documentation describing the variable scheme should be sufficient, but if someone wished to have more verbose documentation (i.e., self-documenting variable names), that is certainly a good option (one that I employ often). One thing that I know I struggle with at times is variable management--a variable for this and that and something else. Why have two variable names when one can be sufficient? Using an array encapsulates (crudely) the initial value with the value which will vary--depending on programmer and situation, this aids variable management.

I'm not suggesting that my suggestion works better or is more efficient . . . just that it is simply an option.

 
Thirteen:

I'm not suggesting that my suggestion works better or is more efficient . . . just that it is simply an option.

Yes, of course
 
parham.trader: suppose that you've given values to some variables at the start of the day as their initial value and by starting the program,it constantly changes these variable as time passes . and then you want to use the initial values for the new day which starts from 00:00.
#define HR2400 86400       // 24 * 3600
int      TimeOfDay(datetime when){  return( when % HR2400          );         }
datetime DateOfDay(datetime when){  return( when - TimeOfDay(when) );         }
datetime Today(){                   return(DateOfDay( TimeCurrent() ));       }
datetime Tomorrow(){                return(Today() + HR2400);                 }

datetime nextReset;
type1    variable;  void OnInitFunction1(){
   variable = INITIAL_VALUE; nextReset = Tomorrow();
}
type2 Function1(){
   if( TimeCurrent() >= nextReset ) OnInitFunction1();
   Print("using ", variable);
   :
 

thank you all;

it has been solved !