Page 3 of 3
Re: Writing to a file
Posted: Fri Jul 01, 2016 6:33 am
by FourthWorld
mwieder wrote:...it's bad form to name a control as a keyword. Button "Save" is bound to cause trouble sometime.
I'm doomed: I have buttons named "Save", and "Open", and other keywords. Been doing it for almost three decades. With English-like languages, avoiding keywords in object names seems so difficult it never occurred to me to try.
Re: Writing to a file
Posted: Fri Jul 01, 2016 9:19 am
by [-hh]
RossG wrote:
Label will change to "Open...."
I want this button to open the file just saved in Notepad
or the default prog. for .txt files.
As I already said above:
launch document <filePath>
does exactly that. So you may change the first part of your button's script to:
Code: Select all
-- works on Mac/Win/Linux
on mouseUp
global fName,newSFP
if word 1 of the label of me = "Open" then
LAUNCH DOCUMENT (newSFP & "/" & fName) # <--- Uses current system's launch service
else
...
Re: Writing to a file
Posted: Fri Jul 01, 2016 6:35 pm
by jacque
I have buttons named "Save", and "Open", and other keywords. Been doing it for almost three decades.
It works because you follow good form and always quote literals. Me too. The first thing I do when working on a novice's stack is go though and add the quotes.
Re: Writing to a file
Posted: Fri Jul 01, 2016 8:13 pm
by mwieder
Jacque-
No, part of my suggestions was to quote literals. They weren't quoted.
Re: Writing to a file
Posted: Fri Jul 01, 2016 8:16 pm
by mwieder
And Ross-
A control's label and name are different things.
You can still have the label read "Save", while the name can be "btnSave" or "helpMeObiWanKenoi" or whatever you want to keep you out of trouble. But using reserved keywords for control names *especially if you're not quoting them* is heading for trouble.
Re: Writing to a file
Posted: Fri Jul 01, 2016 8:23 pm
by RossG
-hh
Just what I needed. I missed it in your earlier post
as it seemed an afterthought.
Code: Select all
-- works on Mac/Win/Linux
on mouseUp
global fName,newSFP
if word 1 of the label of me = "Open" then
LAUNCH DOCUMENT (newSFP & "/" & fName) # <--- Uses current system's launch service
else
...
re: naming a button "Save" it's easy enough to change but "if it ain't broke..."
Mark: One more "/" gives the same error as the LC installer when I try to install
anywhere but the default location i.e. a path with "//" instead of "/".
Inverted commas: seem to be optional...I'm a "just in time" fan and a minimalist
when it comes to typing even though I use ten fingers.
Once again gentlemen thank you for your time and help.
Re: Writing to a file
Posted: Fri Jul 01, 2016 8:55 pm
by mwieder
Mark: One more "/" gives the same error as the LC installer when I try to install
anywhere but the default location i.e. a path with "//" instead of "/".
Ah. Sorry... I wasn't trying to suggest doubling the slash. Just that you were missing the slash in the "Open" part of your "if" conditional statement. There are three lines there that should have a slash added between the newSFP and fName variables. It works if you add the slashes in there, but the effect is the same as Herman's suggestion (and notice that he also inserts the slash there).
At any rate, I'm glad it's working for you now.