Monday, September 12, 2011

Change the date on your computer

Some dangerous lack of soft modularity in VBA.

Forgetting that Date was a datatype, I went ahead and used this little code in VBA for an excel app.


Date = Now()
countdown = Date - 20
...
Date = Date - 20


I started getting inconsistent values for Date every time I ran the program, and realized Date was actually decreasing over time. I checked my system clock and was fooled at first since the system date (on the Windows toolbar) matched the same date as Date.

Didn't take a while to realize that the system clock was wrong too!

So I suppose I was changing the value of Now(), Date, and the system date itself by modifying it! ridiculous!

To fix this, I just added back the missing days to the Date variable.

No comments:

Post a Comment