fontFace, fontStyle, and fontSize

Here is a recent email from a customer: Is there a code you know of…. to use in the Command Window that would change the text of a field to:

font = ms sans serif, font style = bold, size = 14.

I am have to change several fields (not all) to this and looking for a faster method than highlighting and clicking on all the info to change.

Here is my response:

Good idea. Easiest is to select the field in question and use this script in the Command Window:

fontFace of selection = "ms sans serif"; fontStyle of selection = "bold"; fontSize of selection = 14

If you don’t see the results, the text itself may have a different font applied. In that case, you can use this script:

fontFace of text of selection = "ms sans serif"; fontStyle of text of selection = "bold"; fontSize of text of selection = 14

Setting SkipNavigation via the Command Window

The code below shows how to implement the logic of the “Set SkipNavigation” DevEx tool if you wanted to do it in the Command Window. 18 is the first page number in the range and 29 is the last page number. In DevEx tool itself, you need to read the starting and ending page numbers from fields and do some error checking to make sure the book has that many pages and so forth. But this code shows the main logic.

step num from 18 to 29
 pageId = page num
 skipNavigation of pageId = true
end step


ToolBook: Going to the Next Page on Ctrl + Page Down

I had this question from one of our Learning & Mastering ToolBook CD customers this morning and thought it would be a good post.

I am trying to get a learner to click Ctrl + Page Down to get to the next screen. Where can I find instructions on how to do that? 

My response: I would try adding an Action at the page level and handling the keyDown event. The first task is to figure out the keyCode for Page Down. Put in an alert on the keyCode parameter as shown below.

Go to reader mode and press the Page Down key. You’ll see an alert with 34 as shown below:

Next, you need to figure out how to go to the next page. Easiest is to trigger the next page button on the background. However, if you are using SmartPages, the Actions Editor can only “see” the group and not the buttons. But there is a LiveXtension for this as shown below:

You can now Trigger the next page button as shown. This has the advantage of NOT working if that button is disabled, such as when you disable it while they are watching a video.

Note that you probably want to put this on the background so that it works on all pages using that background. Be sure to publish to HTML and then test there as sometimes things work differently in the browser.

Adding a Paint Object Programmatically

For the ToolBook 11 version of Learning & Mastering ToolBook 11, we wanted to add the “Configuring LiveXtensions” button and associated graphic to a training page. However, the page was programmed to show and hide paint objects. Starting with ToolBook 10.5, however, the option to import paint objects was taken out. Instead, inserting a graphic now creates a bitmap resource and image object. We COULD have converted the other paint objects to resources and image objects, but why do that when we can still get a paint object via OpenScript using the code to below. The only slight snag is that the graphic was originally a .png. That wouldn’t import but the .bmp version worked fine.

importgraphic "C:\Users\Jeff\ToolBookProducts\ICBT110\training\resources\icbt2\update\LiveXtensionsConfiguration.bmp"

Enabling or Disabling Voice Recordings

How would you write a tool like the “Voice Recording Toggle” that is available via LiveXtensions in ToolBook? The first task is to figure out how the enabling happens. If you check the “Enable voice recording playback for this page” box on the Voice Recordings tab of the Properties for Page sheet and then check the User Properties of the page using the Property Browser, you’ll see that it adds a property called TBK_VoiceRecordings. It is true if recordings are enabled and false otherwise. That leads to an implementation from the Command Window like the code below. Notice how we check whether the property of the page is NULL. That keeps us from setting the property where there is no voice recording in the first place.

isEnabled = TRUE
step num from 1 to pageCount of this book
	pageId = page num
	if TBK_VoiceRecording of pageId <> NULL
		TBK_VoiceRecording of pageId = isEnabled
	end if
end step

International Date Formats

Question: I need to get out of my provincial ways and format dates appropriate to the local preference (i.e., US, European, etc). Are there any functions I could take advantage of in ToolBook to make my path easier for localization of date formats?

The function below from our TBK Tracker product should be helpful. In early versions, we ran into problems with dates stored in an Access database on the user’s machine being in a different format than what we expected in ToolBook. This was particularly true in regions that put the day first (25/2/2014 as opposed to 2/25/2014).

to handle tbk_setSysDateFormat
	-- if not ASP mode, converts registry date 
	-- format to ToolBook equivalent
	-- else gets ToolBook date format from ASP 
	-- page

	system string s_originalSysDateFormat, 
		s_fileDir, s_tbk_iniFile, s_tbk_dbType

	local string newFormat, blkSus, errorString, aspPage
	local word offsetNum

	if s_originalSysDateFormat <> NULL 
		-- already set
	end if

	if s_tbk_dbType = "ASP" -- get date format 
		-- from server-side ASP page
		aspPage = tbk_getASPPage("formatData")
		get platte_SetHTTPPostParameter("formatType", "date")
		s_originalSysDateFormat = platte_HTTPPost(aspPage)
		if s_originalSysDateFormat = null
			s_originalSysDateFormat = "mm/dd/y"
		end if
	else -- use date format of client machine
		blkSus = ASYM_blockSuspend()
		newFormat = RegistryGetKey("HKEY_CURRENT_USER\ControlPanel\International", \
		errorString = ASYM_restoreSuspend(blkSus)
		if (errorString <> null) OR (newFormat = null) 
		    -- unable to read date format 
			-- from registry; try win.ini
			newFormat = getWinIniVar("intl", "sShortDate")
			if (newFormat = null) OR (ASYM_isNumber(newFormat) = TRUE) 
				-- unable to read from ini file
				s_originalSysDateFormat = sysDateFormat -- default
			end if
		end if

		-- year
		offsetNum = offset("yyyy", newFormat)
		if offsetNum <> 0
			chars offsetNum to (offsetNum + 3) of newFormat = "y"
		end if

		-- month
		if offset("MMM", newFormat) = 0 -- leave 
			-- alone if contains MMM; else make 
			-- lower case
			newFormat = lowerCase(newFormat)
		end if

		-- day
		-- no conversion req'd

		s_originalSysDateFormat = newFormat
	end if
end tbk_setSysDateFormat

You can skip the “ASP” part. The rest reads the registry and uses that to set the s_originalSysDateFormat system variable. When it comes time to display a date, we temporarily set sysDateFormat to this variable. The rest of the time, we set sysDateFormat to “seconds” since we use the sysDate for time tracking. You likely could just set sysDateFormat once.

Avoiding “Save Current Changes” Message

Question: Does anyone know how to eliminate the “Save current changes?” message when the user hyperlinks from one book to another?

Answer: You can set the saveOnClose property of the book to No. Easiest way to do this is to go to Properties for Book – General Tab. Set the “Save on Close” ComboBox to Never. Or you could go to the Command Window and use this script:

saveOnClose of this book = "No"

Be careful though, as doing this will keep you from being prompted to save changes in author level as well. If you want to be prompted at author level, you could put this in your book script:

to handle enterApplication
	if sysRuntime = TRUE -- runtime ToolBook
		saveOnClose of this book = "No"
	else -- author level ToolBook
		saveOnClose of this book = "Ask"
	end if
end enterApplication