Printing all the fields on a card

This lesson demonstrates how to print the content of all the fields on a card.

The printAllFields command

The printAllFields command prints the contents of all the fields on the current card. The command takes no parameters, the syntax of the command is:

printAllFields

Styled text

When manipulating data in variables, LiveCode treats everything as text. This means, among other things, that when you get the contents of a field, any style information, such as boldfacing and fonts, is lost. Only the plain text is retained. To retain the style information in a text field, or to add styles to a variable before printing it, the htmlText property is used to produce HTML-like markup whose style information is understood by LiveCode.

Collecting the text of the fields

The repeat control structure in this handler is used to collect the text of all the fields on the current card. First comes the field name followed by a colon, and next the field contents. The field name is surrounded by tags that turn it into a separate paragraph (<p> and </p>) and make it boldfaced (<b> and </b>). The handler gets the content of the field by getting its htmlText property, which includes the style information in the form of HTML-like tags.

repeat with tField = 1 to the number of fields
	## collect data in the tCollectedFields variable:
	put "<p><b>" & the short name of field tField \
		& colon & "</b></p>" \
		& the htmlText of field tField after tCollectedFields
end repeat

All this information is placed in a single variable called tCollectedFields. Because the htmlText of a field always starts with a <p> tag and ends with a </p> tag, there's no need to separate the parts of the variable with return characters; the htmlText provides the necessary line breaks.

Printing the field data

Once the data is collected into a variable, the handler prints that variable. (The revPrintText command looks for HTML tags in the text to be printed: if the text includes tags, revPrintText assumes the text is in HTML and prints it as styled text.)

revShowPrintDialog false, true
revPrintText tCollectedFields

The printAllFields command code

on printAllFields
	local tField, tCollectedFields
	repeat with tField = 1 to the number of fields
		## collect data in the tCollectedFields variable
		put "<p><b>" & the short name of field tField \
			& colon & "</b></p>" \
			& the htmlText of field tField after tCollectedFields
	end repeat
	
	## print the variable
	revShowPrintDialog false, true
	revPrintText tCollectedFields
end printAllFields

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.