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.mwieder wrote:...it's bad form to name a control as a keyword. Button "Save" is bound to cause trouble sometime.
Writing to a file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 10050
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Writing to a file
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Writing to a file
As I already said above: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.
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
...
shiftLock happens
Re: Writing to a file
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.I have buttons named "Save", and "Open", and other keywords. Been doing it for almost three decades.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Writing to a file
Jacque-
No, part of my suggestions was to quote literals. They weren't quoted.
No, part of my suggestions was to quote literals. They weren't quoted.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: Writing to a file
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.
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.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: Writing to a file
-hh
Just what I needed. I missed it in your earlier post
as it seemed an afterthought.
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.
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
...
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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
Re: Writing to a file
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).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 "/".
At any rate, I'm glad it's working for you now.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev