Open and Close for access

I have played around with trying to write data to a text edit document before and anyway this is what’s going on. I can open for access a file, read the file and apparently write to the file, but if I try to open that file with text edit it says that the file is corrupt or some such and cannot open the file. Is this normal? I got to playing around with this again while experimenting with things in the standard additions dictionary. It wasn’t too long ago (from a post here) that I even knew that this existed (eventhough I have been using elements from there for a while). Here’s the code.

set theFile to choose file
try
	open for access theFile with write permission
end try

set theText to read theFile from 185.55 for 300 -- another question comes in here. The dictionary says that these numbers should be double integers? Just what does that mean. (Unless I have forgotten what an integer is I don't believe 185.55 is one but this does not throw an error.)
set x to get eof theFile
display dialog x as string
set theString to "This is the place where I tried entering stuff into this file."
write theString to theFile starting at x
close access theFile
display dialog (summarize theText) with title "The Summary" buttons {"Ok"}

Also, while I’m at it, the text that is read in (from the event log) contains a whole lot of stuff before the actual text that I entered. How do I know where the beginning of the text that I entered (and want to use) actually is? (I’ll look in text edit dictionary, but just incase. . .)

Thanks to all!

PreTech

Model: dual 1.8 G5
AppleScript: 2.1 (80)
Browser: Safari 412.5
Operating System: Mac OS X (10.4)

Is it a rich text doc? Sounds like it with “a whole lot of stuff before the actual text that I entered.” open access/write/close access is for plain text only, as far as I know.

I should also mention the best way to use open/write/close is in a try block. Close access to the file in the expected route and again in the ‘on error’ part. This eliminates busy files that can’t be trashed if an error occurred after opening access but before closing.

-- EXAMPLE CODE
try
	set writeTarget to open for access file theFile
	write theData to writeTarget
	close access writeTarget
on error
	close access writeTarget
end try

Oh, and one other thing. A double is a floating point number. The value range is from 2.22507385850721e-308 through 1.79769313486231e+308. Storage size is 8 bytes. The range and storage precision is machine dependent.

Thanks for the info!:slight_smile:

PreTech

Just a little note. The highest number “should” be “1.797693134862316e+308” (hex “0x7FEFFFFFFFFFFFFF”), but high precission doesn’t exist in AS. In fact, we can create a higher number (at least in this machine):

(run script "(65536 ^ 63.99999999999999)") + (1024 ^ 98.047)
--> 1.79769313486232E+308

Which is not a “real” number (at least in current computers, as far as I know, though in the “real” world you can sit in a chair and start concatenating numbers thru the end). :confused:

Thanks for the correction, jj. And that’s great info on making the higher number.