HyperCard: Cannot Write Null Characters Without X-Command


There is, at present, no easy way for HyperCard to write a Null character --
hex 00 -- into a text file using "write <source> to file <file name>".

A Null character like hex 00 is often used as a formatting flag in text
documents.

Here is a HyperCard script a user has written to demonstrate the problem:

on mouseUp
open file "i/o test"
write "+++" to file "i/o test" -- so we can see where the information starts
write empty to file "i/o test" -- try to put the null constant into file
write "*" to file "i/o test" -- a marker after the null char.
repeat with x = 0 to 10
write the numToChar of x to file "i/o test" -- try to generate it this way
end repeat
write "+++" & empty & "*" to file "i/o test" -- try to put a null in a string
write "eof" to file "i/o test" -- write out an end of file marker for us
beep 2
close file "i/o test"
end mouseUp

Hypercard uses the C string format in which the Null is identified as the
"end of string" marker. When HyperCard converts the variable in numToChar,
the result of numToChar is placed into a container as a string, which in
this case is a Null, interpreted as the "end of string", and thus ignored.

The only way HyperCard can currently place a Null character into a text file
would be through an XCMD or XFCN.


Published Date: Feb 18, 2012