Page 1 of 1
defaultfolder won't work inside a URL file statement?
Posted: Sat Jan 07, 2017 1:08 am
by Ed_Ray
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.
Re: defaultfolder won't work inside a URL file statement?
Posted: Sat Jan 07, 2017 12:05 pm
by Klaus
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
Re: defaultfolder won't work inside a URL file statement?
Posted: Sun Jan 08, 2017 3:11 am
by Ed_Ray
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.
Re: defaultfolder won't work inside a URL file statement?
Posted: Sun Jan 08, 2017 12:02 pm
by Klaus
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!
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
Re: defaultfolder won't work inside a URL file statement?
Posted: Mon Jan 16, 2017 1:14 pm
by MaxV
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
Re: defaultfolder won't work inside a URL file statement?
Posted: Mon Jan 16, 2017 7:53 pm
by Klaus
No bug, Max, just really bad concatenating of a string!
Didn't you read my second (lengthy) reply?
Re: defaultfolder won't work inside a URL file statement?
Posted: Tue Jan 17, 2017 9:29 am
by MaxV
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.

Re: defaultfolder won't work inside a URL file statement?
Posted: Tue Jan 17, 2017 11:37 am
by Klaus
Yes, just as I already wrote in my first posting.
