oldummy wrote: ↑Sat Jan 13, 2024 1:54 pm
Code: Select all
on mouseUp
open file "myletter"for write--I tried this without the"for write" as well.
...
I think you need to provide
either a
filepath instead of a file name,
or you need to
designate the defaultFolder -- otherwise it defaults to the last used DefaultFolder or the app/engine.
The dictionary is helpful and clear:
Dictionary on 'Open File' wrote:open file <filePath> [for [ {[<encoding>] text | binary}] {update | read | write | append}]
filePath
Specifies the name and location of the file you want to open or create. If you specify a name but not a location, LiveCode assumes the file is in the defaultFolder. If the file you specify doesn't exist, LiveCode creates it unless the containing folder you specify also doesn't exist, in which case the command fails and the result function returns "Can't open that file.".
Dictionary on DefaultFolder wrote: When a LiveCode application starts up, the defaultFolder initially contains whatever the working directory was at the time the application was launched. Typically this is the folder that the application resides in, however this is not always the case and shouldn't be relied on. It is best always to set the defaultFolder before using relative paths.
Also, if opening a file for write, don't forget:
Important: Before opening any file for writing, remember to back up the file contents as LiveCode will erase them even if you do not write to the file after opening it.
So use with caution and use 'open file for append | update' if editing a file.
Perhaps even better just use the get/put URL syntax instead... eg
Code: Select all
put URL ("file:/" & <filepath>) into <text>
-- edit variable/field then
put <text> into URL ("file:/" & <filepath>)