defaultfolder won't work inside a URL file statement?

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
Ed_Ray
Posts: 83
Joined: Sun Jun 19, 2016 12:18 am

defaultfolder won't work inside a URL file statement?

Post by Ed_Ray » Sat Jan 07, 2017 1:08 am

My defaultfolder has been set to: “c:\temp\livecodefiles”
This works: put "This program is trending" into URL "file:c:\temp\livecodefiles\TestingNow.txt"

But the following yields this error: “compilation error at line x (Handler: bad command) near “&” , char xx
put "This program is trending" into URL "file:" & defaultfolder & "\TestingNow.txt"

Is there any reason the concatenation yielding exactly the same string won't work?

Thanks to all in advance.

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: defaultfolder won't work inside a URL file statement?

Post by Klaus » Sat Jan 07, 2017 12:05 pm

Hi Ed,

concatenated strings (for pathnames, object names etc.) need to be in parens to be parsed correctly by the engine!
...
put "This program is trending" into URL("file:" & defaultfolder & "/TestingNow.txt")
...
And if you ever want to develop for other platforms than Windows, get used to the internal LC pathdelimiter which is a SLASH -> /


Best

Klaus

Ed_Ray
Posts: 83
Joined: Sun Jun 19, 2016 12:18 am

Re: defaultfolder won't work inside a URL file statement?

Post by Ed_Ray » Sun Jan 08, 2017 3:11 am

Thanks for the response.
For Klaus:

In the dictionary for the use of “URL file xxx” usage, there is no mention of having to do what you stated (use of a surrounding parenthesis) to make this work so where is this rule specified in the dictionary?

Also I had come up with a work around that does NOT require the use of the parenthesis. Any reason why the workaround (below) works without the need of the surrounding parenthesis?

My work around that worked without the need for a surrounding parenthesis.

put "file:" & defaultfolder & "\TestingNow.txt" into xvar
put "This program is trending" into url xvar --(works perfectly without parenthesis or any compilation errors)

Thanks.

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: defaultfolder won't work inside a URL file statement?

Post by Klaus » Sun Jan 08, 2017 12:02 pm

Hi Ed,

the examples in the dictionary do NOT use concatenated strings!
put "file:" & defaultfolder & "\TestingNow.txt" into xvar
put "This program is trending" into url xvar --(works perfectly without parenthesis or any compilation errors)
Check the content of xvar (or just ANSWER XVAR), here you pass an already concatenated string, so no complains from the engine.

Try this:
Create a button named "My Button"
Now create another button with this script

Code: Select all

on mouseup
  hide button "My" && "Button"
end mouseup
Error: Can't find object...

Change to :
...
hide button ("My" && "Button")
...
Works!

Same here:
...
put "My" && "Button" into tButt
hide button tButt
...
Works, too!

I do not say we ALWAYS have to use parens when concatenating strings, I say it depends! :D

When passing a concatenated string to any handler/function it needs to be in parens since
the engine will first evaluate the expression inside of hte parens and does the concatenating for us.

If not, the engine will only take the part until the first & and tries to use that for the command/function
which, in case of concatenated string, is only "half the rent" and it throws an error.


Best

Klaus

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: defaultfolder won't work inside a URL file statement?

Post by MaxV » Mon Jan 16, 2017 1:14 pm

Ed_Ray wrote:My defaultfolder has been set to: “c:\temp\livecodefiles”
This works: put "This program is trending" into URL "file:c:\temp\livecodefiles\TestingNow.txt"

But the following yields this error: “compilation error at line x (Handler: bad command) near “&” , char xx
put "This program is trending" into URL "file:" & defaultfolder & "\TestingNow.txt"

Is there any reason the concatenation yielding exactly the same string won't work?

Thanks to all in advance.
To me is a bug, because

Code: Select all

put "This program is trending" into URL "file:" & the  defaultfolder & "/TestingNow.txt"
should work
See http://quality.livecode.com/show_bug.cgi?id=19098
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: defaultfolder won't work inside a URL file statement?

Post by Klaus » Mon Jan 16, 2017 7:53 pm

No bug, Max, just really bad concatenating of a string!
Didn't you read my second (lengthy) reply?

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: defaultfolder won't work inside a URL file statement?

Post by MaxV » Tue Jan 17, 2017 9:29 am

Klaus wrote:No bug, Max, just really bad concatenating of a string!
Didn't you read my second (lengthy) reply?
All right,

Code: Select all

    put "This program is trending" into URL "file:" & (the  defaultfolder) & "/TestingNow.txt"
doesn't work, but this

Code: Select all

    put "This program is trending" into URL ("file:" & the  defaultfolder & "/TestingNow.txt")
works.
:D
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: defaultfolder won't work inside a URL file statement?

Post by Klaus » Tue Jan 17, 2017 11:37 am

Yes, just as I already wrote in my first posting. 8)

Post Reply