Writing to a file

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10050
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Writing to a file

Post by FourthWorld » Fri Jul 01, 2016 6:33 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Writing to a file

Post by [-hh] » Fri Jul 01, 2016 9:19 am

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
  ...
shiftLock happens

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Writing to a file

Post by jacque » Fri Jul 01, 2016 6:35 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Writing to a file

Post by mwieder » Fri Jul 01, 2016 8:13 pm

Jacque-

No, part of my suggestions was to quote literals. They weren't quoted.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Writing to a file

Post by mwieder » Fri Jul 01, 2016 8:16 pm

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.

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Writing to a file

Post by RossG » Fri Jul 01, 2016 8:23 pm

-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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Writing to a file

Post by mwieder » Fri Jul 01, 2016 8:55 pm

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.

Post Reply