Reading from an external file

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jessamy99
Posts: 103
Joined: Thu Oct 25, 2012 3:23 pm

Reading from an external file

Post by jessamy99 » Sun Dec 22, 2019 7:10 pm

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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Reading from an external file

Post by Klaus » Sun Dec 22, 2019 7:56 pm

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

jessamy99
Posts: 103
Joined: Thu Oct 25, 2012 3:23 pm

Re: Reading from an external file

Post by jessamy99 » Sun Dec 22, 2019 10:53 pm

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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Reading from an external file

Post by Klaus » Mon Dec 23, 2019 11:44 am

Well, the other way round! :-D

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
...

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Reading from an external file

Post by bogs » Mon Dec 23, 2019 1:36 pm

Klaus wrote:
Mon Dec 23, 2019 11:44 am
OK, better put it into an IF THEN clause:

Speaking about the 'Clause'...
Image

... 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"
...
Image

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Reading from an external file

Post by Klaus » Mon Dec 23, 2019 1:44 pm

Noone likes a wise guy, Starsk.. erm bogs! :D

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Reading from an external file

Post by bogs » Mon Dec 23, 2019 1:52 pm

It is all in the fine print when you read the 'Wise Guy' Clause...Image
:D :D
Image

jessamy99
Posts: 103
Joined: Thu Oct 25, 2012 3:23 pm

Re: Reading from an external file

Post by jessamy99 » Mon Dec 23, 2019 4:45 pm

Thankyou both very much!!

I will have a go.

Have a wonderful Christmas!!

All the best,
Jessamy

jessamy99
Posts: 103
Joined: Thu Oct 25, 2012 3:23 pm

Re: Reading from an external file

Post by jessamy99 » Mon Dec 23, 2019 5:55 pm

It worked!!

Thankyou both - you are angels!!

Much appreciated.
Jessamy

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Reading from an external file

Post by bogs » Mon Dec 23, 2019 7:58 pm

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 Image}]

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

:twisted:
Image

Post Reply

Return to “iOS Deployment”