Page 1 of 1
Putting a text file into variable with URL method not working
Posted: Tue Mar 02, 2021 11:43 pm
by montymay
Hello
It's been a while since a posted a help request because I suspended work on my project, but I'm back on it and could use any suggestions that would correct the following unexpected outcome.
The code below, written for a text field containing a list of topics, with listbehavior and locktext set to true, formerly worked but now the variable tText remains empty after running the code:
Code: Select all
on mouseup
put "D:/Documents/DB/guides/" into tFolder
put the selectedtext of me into tTopic
put url ("file:"&tFolder&tTopic&".txt") into tText
set the htmltext of fld "guide" to tText
end mouseup
The path to the folder containing the text files with the file name being the selected line, is correct. I am running LC 9.6.1. Thank you for any suggestions.
Monty
Re: Putting a text file into variable with URL method not working
Posted: Tue Mar 02, 2021 11:56 pm
by bogs
Which OS ?
Re: Putting a text file into variable with URL method not working
Posted: Tue Mar 02, 2021 11:57 pm
by montymay
Sorry. Windows 10, latest update.
Re: Putting a text file into variable with URL method not working
Posted: Tue Mar 02, 2021 11:59 pm
by bogs
I'll try an test it tomorrow (early morning, most likely) if someone don't beat me to it

Re: Putting a text file into variable with URL method not working
Posted: Wed Mar 03, 2021 12:43 am
by jmburnod
Hi,
This syntax is strange for me
Code: Select all
put url ("file:"&tFolder&tTopic&".txt") into tText
What happend with that instead:
Code: Select all
put tFolder & tTopic & ".txt" into tFile
put url ("file:" & tFile) into tText
Best regards
Jean-Marc
Re: Putting a text file into variable with URL method not working
Posted: Wed Mar 03, 2021 2:15 am
by liveme
Hi Monty,
This works for me !
- differences - I'm only looking for files in the same folder of my stack
Code: Select all
## Get the contents of the file
put URL ("file:" & tFileName) into tFileContents
## Display the file contents in the field
put tFileContents into field "Result"
as you see, very few " " " ... involved - this way is to run it on linux.
*also under windows : some path used symbol will depend if meant for a 32 bits platforms or 64 bits...
Re: Putting a text file into variable with URL method not working
Posted: Wed Mar 03, 2021 9:54 am
by montymay
Hello
Thanks to those who replied. I hope I did not waste too much of your time. I found the problem: there is a hidden character at the beginning of each line of the list field. Modifying the script to delete it fixed the problem. I don't know what the character is or how it got there but will investigate. If there is a way of revealing the hidden character, it would be of interest to others, I think.
Monty
Re: Putting a text file into variable with URL method not working
Posted: Wed Mar 03, 2021 10:14 am
by FourthWorld
What was the character?
Re: Putting a text file into variable with URL method not working
Posted: Wed Mar 03, 2021 11:31 am
by bogs
FourthWorld wrote: ↑Wed Mar 03, 2021 10:14 am
What was the character?
montymay wrote: ↑Wed Mar 03, 2021 9:54 am
I don't know what the character is or how it got there but will investigate
montymay wrote: ↑Wed Mar 03, 2021 9:54 am
I found the problem: there is a hidden character at the beginning of each line of the list field.
Sounds a lot like what I found in this
post 
Re: Putting a text file into variable with URL method not working
Posted: Wed Mar 03, 2021 7:30 pm
by liveme
If there is a way of revealing the hidden character, it would be of interest to others, I think.
whatever character is "hidden" in some way, could be made "visible" when using a Textconversion LC feature;
So just by converting it to another format would show it as a string.
Using a "regex" filter, could also help to instantly remove undesired string wherever it is encountered !
..then you just need to save the "sanitized" string as you wish.
Text "converting" :
https://lessons.livecode.com/m/2592/l/1 ... cii-values
https://livecode.fandom.com/wiki/UniDecode
https://livecode.fandom.com/wiki/FormattedText
...and more
Regex use case :
https://livecode.fandom.com/wiki/Filter
just an idea
