Page 1 of 1

Trying to bring in text to a field from text file

Posted: Tue Aug 18, 2015 9:53 pm
by athelene
I am trying to bring in the text from a text file into a field. I know this should be simple and have done this before in the tutorial on creating a Notes app. Today, I'm trying to do the exact same thing and no luck. I even renamed my file and field to match the tutorial in case I was missing something. So, my field is named notesList and my file is notesList.txt located in my documents folder. I then created the following lines of code. No errors on execution but it did not add the text from the file into the field. The only thing different that I can identify from the time I did the tutorial to today is that I've moved to Win 10. Could that possibly be the issue? If so, any thoughts on how to get around it? Or, can you see what I might be doing wrong? I have to say I'm about to throw in the towel. If I can't get this small piece to work more than once, I'm probably not cut out for using this tool. (sigh)

put specialFolderPath("documents") & "/notesList.txt" into tFile
put URL("File:" & tFile) into field "notesList"

Result: No errors, no change in field notesList. If it matters, notesList field is a scrolling field as used in the tutorial. I've quadruple checked to ensure the proper location of my file.

Any thoughts would be much appreciated!

Re: Trying to bring in text to a field from text file

Posted: Tue Aug 18, 2015 10:09 pm
by FourthWorld
athelene wrote:If I can't get this small piece to work more than once, I'm probably not cut out for using this tool. (sigh)
If I can use it certainly you can.

One thing that may be helpful is to keep in mind that LiveCode has two types of errors: only the most serious unrecoverable errors will throw an actual error dialog, while for the others we can check a global variable immediately after a command to see if it contains error info, "the result":

Code: Select all

put URL("File:" & tFile) into field "notesList"
if the result is not empty then
   answer the result &"( "& sysError() &")"
end if
In addition to checking the result, I've also added a call to the sysError function, useful for file I/O stuff as it'll tell you the OS error code number if an error has occurred.

Add that to your script and try it out, and let us know what you find.

Re: Trying to bring in text to a field from text file

Posted: Tue Aug 18, 2015 10:14 pm
by athelene
OK! Says: Can't open file (87) Does the 87 point me to any resource that might tell me why it can't open it? Maybe my quadruple check on location was quadruple times wrong?

Can't tell you how much I appreciate your help.

Re: Trying to bring in text to a field from text file

Posted: Tue Aug 18, 2015 10:47 pm
by Simon
Hi athelene,
Here is a quick way to make sure you are in the right place

Code: Select all

answer file "Pick a file?"
put URL("File:" & it) into field "notesList"
put it
"it" will contain the complete path to the file.

Simon

Re: Trying to bring in text to a field from text file

Posted: Tue Aug 18, 2015 11:14 pm
by athelene
Thank you!!! Figured it out with your last bit of help. Feeling even more stupid as a result, but very grateful. Turns out the file name was actually notesList.txt.txt. My File Explorer was not showing me extensions. Apparently Livecode can't read my mind and figure out that I am using the wrong filename. Go figure! Anyway, I very much appreciate all the super fast help for this beginner!

I kind of feel like I always feel on the 18th hole of the golf course. You have a lousy game for the first 17 holes. But when you finally get a birdie on 18, you think it's the best game ever and can't wait to play again. :lol:

Have a good evening everyone.

Re: Trying to bring in text to a field from text file

Posted: Wed Aug 19, 2015 1:03 am
by FourthWorld
athelene wrote:Thank you!!! Figured it out with your last bit of help. Feeling even more stupid as a result, but very grateful. Turns out the file name was actually notesList.txt.txt. My File Explorer was not showing me extensions.
That's not you, that's some OS designer who felt it would be better if the system presented incomplete information to you. File extensions can be very important, and when an OS conceals them from users it gives rise to about as many issues as that design decision is supposed to fix.
Apparently Livecode can't read my mind and figure out that I am using the wrong filename.
Support for psychic code interpretation is slated for v21. ;)
I kind of feel like I always feel on the 18th hole of the golf course. You have a lousy game for the first 17 holes. But when you finally get a birdie on 18, you think it's the best game ever and can't wait to play again. :lol:
Good to see you're still in the game. LiveCode is a strange beast sometimes, different from just about any other programming system you'll find. But for that reason it's also strangely addictive.

Re: Trying to bring in text to a field from text file

Posted: Wed Aug 19, 2015 7:19 am
by SparkOut
It never ceases to amaze me that someone decided to make a feature to hide the extensions, and especially that it is turned on by default.