Putting a text file into variable with URL method not working

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
montymay
Posts: 145
Joined: Thu Jul 18, 2013 5:23 am

Putting a text file into variable with URL method not working

Post by montymay » Tue Mar 02, 2021 11:43 pm

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

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

Re: Putting a text file into variable with URL method not working

Post by bogs » Tue Mar 02, 2021 11:56 pm

Which OS ?
Image

montymay
Posts: 145
Joined: Thu Jul 18, 2013 5:23 am

Re: Putting a text file into variable with URL method not working

Post by montymay » Tue Mar 02, 2021 11:57 pm

Sorry. Windows 10, latest update.

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

Re: Putting a text file into variable with URL method not working

Post by bogs » Tue Mar 02, 2021 11:59 pm

I'll try an test it tomorrow (early morning, most likely) if someone don't beat me to it :D
Image

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Putting a text file into variable with URL method not working

Post by jmburnod » Wed Mar 03, 2021 12:43 am

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
https://alternatic.ch

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm
Location: down under

Re: Putting a text file into variable with URL method not working

Post by liveme » Wed Mar 03, 2021 2:15 am

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

*also under windows : some path used symbol will depend if meant for a 32 bits platforms or 64 bits...

montymay
Posts: 145
Joined: Thu Jul 18, 2013 5:23 am

Re: Putting a text file into variable with URL method not working

Post by montymay » Wed Mar 03, 2021 9:54 am

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Putting a text file into variable with URL method not working

Post by FourthWorld » Wed Mar 03, 2021 10:14 am

What was the character?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Putting a text file into variable with URL method not working

Post by bogs » Wed Mar 03, 2021 11:31 am

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
:D
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 :roll:
Image

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm
Location: down under

Re: Putting a text file into variable with URL method not working

Post by liveme » Wed Mar 03, 2021 7:30 pm

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 :idea:

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”