Page 1 of 1
Reading from an external file
Posted: Sun Dec 22, 2019 7:10 pm
by jessamy99
Hi Team,
I am struggling with a silly thing here, and I am sure it is easy!!
I hope you can help me.
I am writing to a text file in Documents...
open file specialFolderPath("documents") & "/myFood" & ".txt" for write
replace tab with ", " in field "email body" of card "email"
put field "email body" of card "email" into Food
write Food to file specialFolderPath("documents") & "/myFood" & ".txt"
close file specialFolderPath("documents") & "/myFood" & ".txt"
I want to write it into the App when it is opened.
I have tried many ways of wording it!!!
I appreciate your help as always,
All the best,
Jessamy
Re: Reading from an external file
Posted: Sun Dec 22, 2019 7:56 pm
by Klaus
Hi Jessamy,
you
HAVE TO USE PARENTHESIS when concatenating file- and/or object names!
And maybe I can interest you in the shorter URL syntax? That is a ONE-liner!
Code: Select all
...
replace tab with ", " in field "email body" of card "email"
## No parens neccessary when you put the file- or objectname into a variable first!
## Which also saves a lot ot typing! 8-)
put specialFolderPath("documents") & "/myFood.txt" into tFile
put field "email body" of card "email" into url("file:" & tFile)
...
With your syntax you need to do like this:
Code: Select all
...
open file (specialFolderPath("documents") & "/myFood.txt") for write
replace tab with ", " in field "email body" of card "email"
put field "email body" of card "email" into Food
write Food to file (specialFolderPath("documents") & "/myFood.txt")
close file (specialFolderPath("documents") & "/myFood.txt")
...
You decide what to use.
Best
Klaus
Re: Reading from an external file
Posted: Sun Dec 22, 2019 10:53 pm
by jessamy99
Thankyou Klaus!
Yes, your method looks much neater!
But how do I read the file back into the app?
It is probably my fault for not being clear.
I want to copy the contents of the file into a field.
Best wishes,
Jessamy
Re: Reading from an external file
Posted: Mon Dec 23, 2019 11:44 am
by Klaus
Well, the other way round!
Code: Select all
...
put specialFolderPath("documents") & "/myFood.txt" into tFile
put url("file:" & tFile) into field "email body" of card "email"
...
OK, better put it into an IF THEN clause:
Code: Select all
...
put specialFolderPath("documents") & "/myFood.txt" into tFile
if there is a file tFile then
put url("file:" & tFile) into field "email body" of card "email"
end if
...
Re: Reading from an external file
Posted: Mon Dec 23, 2019 1:36 pm
by bogs
Klaus wrote: ↑Mon Dec 23, 2019 11:44 am
OK, better put it into an IF THEN clause:
Speaking about the 'Clause'...
... you could make that a one liner -
Code: Select all
...
put specialFolderPath("documents") & "/myFood.txt" into tFile
if there is a file tFile then put url("file:" & tFile) into field "email body" of card "email"
...
Re: Reading from an external file
Posted: Mon Dec 23, 2019 1:44 pm
by Klaus
Noone likes a wise guy, Starsk.. erm bogs!

Re: Reading from an external file
Posted: Mon Dec 23, 2019 1:52 pm
by bogs
Re: Reading from an external file
Posted: Mon Dec 23, 2019 4:45 pm
by jessamy99
Thankyou both very much!!
I will have a go.
Have a wonderful Christmas!!
All the best,
Jessamy
Re: Reading from an external file
Posted: Mon Dec 23, 2019 5:55 pm
by jessamy99
It worked!!
Thankyou both - you are angels!!
Much appreciated.
Jessamy
Re: Reading from an external file
Posted: Mon Dec 23, 2019 7:58 pm
by bogs
jessamy99 wrote: ↑Mon Dec 23, 2019 5:55 pm
- you are angels!!
Well, Klaus's picture on his union card seems to suggest as much - [Klaus Major {Angel

}]
My form looks a tad different though... [Bogs Thing {Ummm...

}]
