HyperCard: How To Find Character Number in a Field



How can I return the "number" of the first character of a line in a HyperCard
field?

Since each TextEdit Record contains an array containing the number of the first
character of the line, I'd like to access that information.

You can find the number of the first character of line x in a HyperCard
field by using the following script:

if x = 1
then
put 1 into charNum
else
put (the length of line 1 to (x-1) of fld test) + 1 into charNum
end if

The only problem with the script is that HyperCard considers a line as a line
only if it is terminated with a carriage return. Line endings that result from
word-wrap in a field are not counted as lines.

For example, a field set to display eight characters wide is filled with 20,000
characters without a carriage return. The display shows approximately x lines,
but HyperCard considers the field to only have one line.

Since HyperCard returns only a null-terminated string of characters as field
contents, you cannot use an XCMD to retrieve the line-starts information.


Published Date: Feb 18, 2012