maybe declaring tFile as a local variable will help?

Code: Select all
local tFile
on preOpenCard
...
put url("file:tAgent.txt") into tfile
end preOpenCard
on opencard
...
Klaus
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Code: Select all
local tFile
on preOpenCard
...
put url("file:tAgent.txt") into tfile
end preOpenCard
on opencard
...
Simon & KlausSimon wrote:Hi Tom,
First glance:
You haven't defined "tfile" as a local variable, it gets lost after preOpenCard.
While not really a problem, in the on mouseUp you don't have to put the field into a variable first, just;
put fld "Aname" into line 1 of tfile
Simon
Edit; I see Klaus beat me to it
Code: Select all
global tfile
on preOpenCard
## Save some typing:
put specialFolderPath("documents") & "/sellnet" into tFolder
put tFolder & "/tAgent.txt" into tFilePath
if there is not a folder tFolder then
create folder tFolder
## No else case? Then no ELSE necceessary!
##else
end if
## ALWAY check for exitsence of files before you try to access them!
if there is a file tFilePath then
put url("file:" & tFtFilePath) into tfile
## Check for correct content!
ANSWER tFile
else
ANSWER "File not present (yet)!"
end if
end preOpenCard
on openCard
-- this loads the saved data into the fields on card 5 which are used later
-- it is done when the app begins or when the user send the program here to edit the data
put line 1 of tfile into fld "Aname" of card 5
put line 2 of tfile into fld "Aoffice"of card 5
put line 3 of tfile into fld "Acell"of card 5
put line 4 of tfile into fld "officep"of card 5
put line 5 of tfile into fld "Aemail"of card 5
-- Fld begin is = "T" on app startup
if fld "begin" of card 1 ="T" then
put "F" into fld "begin" of card 1
go card 1
end if
--if the user directed the program here then stay on the card to edit data and save with the finish button
end openCard
############################################################################
global tFile
on mouseUp
## Not neccessary, since you use an absolute path later!
## set the defaultFolder to (specialFolderPath("documents") & "/sellnet/")
put fld "Aname" & cr & fld "Aoffice" & cr & fld "acell" & cr & fld"Officep" & cr & fld"Aemail" & cr into tfile
--save the updated file to disk
put tfile into url("file:" & (specialFolderPath("documents") & "/sellnet/tagent.txt"))
## THE RESULT must be empty on success!
ANSWER THE RESULT
end mouseUp
AndroidKlaus wrote:Quick question: Is this on the desktop or mobile platform?
I have all folder and file names in lower case now.Klaus wrote:Ah, thamks.
Hm iOS file system is case sensitive, is Android, too?
If yes, then tAgent.txt <> tagent.txt! and should be corrected:
...
put tFolder & "/tAgent.txt" into tFilePath
...
put tfile into url("file:" & (specialFolderPath("documents") & "/sellnet/tagent.txt"))
...
To avoid this mess, I ALWAYS use lowercase for file- and foldernames on mobile!
Code: Select all
...
put tFolder & "/tAgent.txt" into tFilePath
...
Code: Select all
...
put tFolder & "/tagent.txt" into tFilePath
...
Klaus wrote:Hi Tom,
did you change this:to this:Code: Select all
... put tFolder & "/tAgent.txt" into tFilePath ...
?Code: Select all
... put tFolder & "/tagent.txt" into tFilePath ...
Best
Klaus
Thanks Simon,Simon wrote:Hi Tom,
Are you reading the text file to see if the info is correct each time you change it? (make sure you close it so it can be written to).
Simon
The "url("file:" xyz) syntax does ecactly this in a one-liner:Simon wrote:Are you reading the text file to see if the info is correct each time you change it? (make sure you close it so it can be written to).