Putting the Current Year in a ToolBook Field

In our Learning & Mastering ToolBook training, we have a page that displays the “Starting Year.” How do we make sure that this field has the current year in it rather than the year we wrote the training? We use the script below.

notifyBefore enterPage
	local oldDateFormat
	oldDateFormat = sysDateFormat
	sysDateFormat = "y"
	text of self = sysDate
	sysDateFormat = oldDateFormat
end enterPage

We handle the enterPage event using the notifyBefore syntax since the field does not receive that message on its own. We then create a local variable to hold the current sysDateFormat. We need that so we can set the sysDateFormat back when we are done. We then set the sysDateFormat to “y” so we get just the numeric year (such as 2014). We then set the text of self to be the sysDate. Finally, we set the sysDateFormat back. This is good practice in case other code (like our Progress Tracker in this case) is relying on sysDateFormat being a particular value.

Notice that this code would have initialized a DHTML application to the year in which it was published. Not quite as good as updating it at runtime, but not too bad.


About Jeff Rhodes
Jeff Rhodes is the Chief Technical Officer and owner of Platte Canyon Multimedia Software Corporation, a leader in developing commercial software that Improves the Lives of Training Developers. He graduated at the top of his class at the Air Force Academy, where he earned a Bachelor of Science in Electrical Engineering. Jeff received a Masters degree in Economics from the London School of Economics, which he attended under a British Marshall Scholarship. Jeff is the author of "Programming for e-Learning Developers: ToolBook, Flash, JavaScript, & Silverlight" and "VBTrain.Net: Creating Computer and Web Based Training with Visual Basic .NET." He also co-wrote "The ToolBook Companion." He has had numerous articles on training development published and is a frequent presenter at conferences both in the U.S. and Europe. Jeff lives in Colorado Springs with his wife Sue and sons Derek and Michael.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: