Something puzzled me for the last few minutes, figured it out and thought I post it for others for reference value.
I have a script that runs in the OnChange event of an object on a form.
On testing the script, it seemed to run twice for no logical reason.
When placing the same script in the OnDepart event, it runs once!
There is so many complicating factors, for instance the script takes part of the name of the object and runs based on that part and when departing from one object to another where that part of the name is identical in both objects, made it rather more difficult to decipher what was happening thinking maybe it did so because of the similarity in that part of the name.
But that wasn't it.
It dawned on me that one line of of the script changes the value of the object itself under certain conditions. That change is done through evaluate_template() that takes the object's name and changes its value.
I began to wonder, if when evaluate_template() executes and changes the value of the object you are in and if that object has an OnChange event, I began to wonder if that triggers the OnChange event, yet again?
Upon further testing, I found out that it does, hence the script runs twice When placed in the OnChange, but only once when placed in the OnDepart.
Just keep that in mind for future reference to save yourself few minutes (or hours) of pondering and puzzling.
I have a script that runs in the OnChange event of an object on a form.
On testing the script, it seemed to run twice for no logical reason.
When placing the same script in the OnDepart event, it runs once!
There is so many complicating factors, for instance the script takes part of the name of the object and runs based on that part and when departing from one object to another where that part of the name is identical in both objects, made it rather more difficult to decipher what was happening thinking maybe it did so because of the similarity in that part of the name.
But that wasn't it.
It dawned on me that one line of of the script changes the value of the object itself under certain conditions. That change is done through evaluate_template() that takes the object's name and changes its value.
I began to wonder, if when evaluate_template() executes and changes the value of the object you are in and if that object has an OnChange event, I began to wonder if that triggers the OnChange event, yet again?
Upon further testing, I found out that it does, hence the script runs twice When placed in the OnChange, but only once when placed in the OnDepart.
Just keep that in mind for future reference to save yourself few minutes (or hours) of pondering and puzzling.
Comment