Does anyone know of a way to get a certain amount of data from a text file, i.e. a text file that contains a list of recipe's in the format:
recipe title:
recipe notes:
recipe ingredients:
recipe directions:
**********
and how to make each recipe appear on a new card?
Text File Manipulation
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
If the text file is relatively small (i.e. < 500K) the easiest way is to read it into a variable as a whole, and go through it line by line from there. Assuming you have setup a background groupo with all the necessary fields (title, notes, ingredients, directions), your import button script could look something like this.
HTH,
Jan Schenkel.
Code: Select all
on mouseUp
answer file "Readh which recipe file?"
if the result is "Cancel" then exit mouseUp
put "file:" & it into tURL
put URL tURL into tData
repeat for each line tLine in tData
if tLine is "recipe title:" then
create card -- start a new recipe card
put "title" into tCurrentField
else if tLine is "recipe notes:" then
put "notes" into tCurrentField
else if tLine is "recipe ingredients:" then
put "ingredients" into tCurrentField
else if tLine is "recipe directions:" then
put "directions" into tCurrentField
else
put tLine & return after field tCurrentField
end if
end repeat
end mouseUp
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
-
- Posts: 78
- Joined: Fri Oct 03, 2008 10:13 am
nearly
Hi Jan, thanks for your reply, i tried the code you posted and it filled two fields correctly: recipe ingredients is ok, recipe directions is ok but recipe Notes has no text and recipe title filled ok but it also has the text from the recipe notes field,
it nearly worked, it think it may just need tweaking slightly.
it nearly worked, it think it may just need tweaking slightly.
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
I'm afraid you'll just have to go and debug it - I can't see a reason why it wouldn't work given your example. Perhaps the import file has an extra space before or after a colon?
Best of luck,
Jan Schenkel.
Best of luck,
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
-
- Posts: 78
- Joined: Fri Oct 03, 2008 10:13 am
Sorted
Thanks Jan,
I managed to get it sorted out in the end,
thanks for your help!
I managed to get it sorted out in the end,
thanks for your help!