Page 1 of 2
Saving a text file
Posted: Wed Jul 12, 2017 8:51 am
by bidgeeman
Hi. (SOLVED)
Oh dear I am a bit silly. I forgot that all the data in the fields are on 1 line so the script kept overwriting
I would still like to know how to add the "TXT" extension automatically instead of having to write in the extension each time if someone could help me with that it would be much appreciated?
Thanks for any help.
Bidge
Code ammended
Code: Select all
on mouseUp
ask file "Save to?" with type "text files|TXT"
put it into tFile
if tFile is empty then
exit mouseUp
else
put line 1 of field "Field1" into line 1 of sRec
put line 1 of field "Field2" into line 2 of sRec
put line 1 of field "Field3" into line 3 of sRec
put line 1 of field "Field4" into line 4 of sRec
put line 1 of field "IWidth" into line 5 of sRec
put line 1 of field "IHeight" into line 6 of sRec
put sRec into URL ("file:" & tFile)
end if
end mouseUp
Re: Saving a text file
Posted: Wed Jul 12, 2017 10:23 am
by jmburnod
Hi,
add the "TXT" extension automatically
Code: Select all
on mouseUp
ask file "Save to?"
if it is empty then exit mouseUp
if char -4 to -1 of it <> ".txt" then
put ".txt" after it
end if
put it into tFile
answer tFile
end mouseUp
Best
Jean-Marc
Re: Saving a text file
Posted: Wed Jul 12, 2017 10:25 am
by Klaus
Hi David,
bidgeeman wrote:I would still like to know how to add the "TXT" extension automatically instead of having to write in the extension each time if someone could help me with that it would be much appreciated?
don't forget that YOU are the developer and thus responsible for EVERYTHING your app will output, so you always have to take care these kind of things by yourself!
Code: Select all
...
ask file "Save to?" with type "text files|TXT"
put it into tFile
if tFile is empty then
exit mouseUp
end if
## One way to ensure a correct suffix:
if NOT (tFile ends with ".txt") THEN
put ".txt" after tFile
end if
put line 1 of field "Field1" into line 1 of sRec
...
Best
Klaus
Re: Saving a text file
Posted: Wed Jul 12, 2017 10:39 am
by bidgeeman
Hi.
My apologies. The scripts work fine thank you. My bad.
Again my thanks to you both.
Bidge
Re: Saving a text file
Posted: Wed Jul 12, 2017 11:34 am
by Klaus
Hi David,
you can add a proposal for a filename and even the location where to save:
Code: Select all
ask file "Save as:" with "a very cool file.txt" with type "text files|TXT"
Or:
Code: Select all
put specialfolderpath("desktop") & "/a cool file.txt" into tFile2Save
ask file "Save as:" with tFile2Save with type "text files|TXT"
It is however likely that the user will overwrite the proposed name AND its suffix, so you still
need to check for this as mentioned above.
Hint:
The "with type XYZ" only works on Windows, it has no meaning on a Mac or Linux!
Best
Klaus
Re: Saving a text file
Posted: Wed Jul 12, 2017 11:36 am
by bidgeeman
Once again thanks Klaus.
It was my learner error which has been corrected.
Bidge
Re: Saving a text file
Posted: Wed Jul 12, 2017 12:19 pm
by bidgeeman
I have one more newbie question with regard to "Snapshots". I need to take a snapshot of a stack and import or export it to an image container on another stack via the clipboard? I am very confused with "import" and "export" commands as opposed to "put" the snapshot into image"Test". What is the correct way to go about this?
Thank you again.
Bidge
Re: Saving a text file
Posted: Wed Jul 12, 2017 12:35 pm
by Klaus
Hi david,
no need for the clipboard!
Code: Select all
...
put the rect of this stack into tRect
export snapshot from rect tRect to img "snap" of cd 3 of stack "another stack"
...
"import snapshot..." will create a new image and will put the screenshot into that new image
"export snapshot..." will let you define the TARGET of the screenshot, being a URL(file on disk) or another image object.
Check the dictionary "export snapshot" for more infos.
Best
Klaus
Re: Saving a text file
Posted: Wed Jul 12, 2017 12:41 pm
by bidgeeman
Ahhh...thanks Klaus.
I was able to import a snapshot from a card directly into a stack but I did not know how to go about implementing the export and import functions. That has cleared things up thank you once again.
The dictionary has become my best friend but sometimes I feel it expects you have a good working knowledge of the language which is what I am struggling with.
Thanks again, you are great teachers !
Bidge
Re: Saving a text file
Posted: Thu Jul 13, 2017 11:10 am
by bidgeeman
Hi.
This is a bit of a general question of which you don't really get from looking at the dictionary but for a newbie it is something I can't find anywhere else other than by asking the experts

Are there any hints or tips when it comes to building a standalone exe? Any snippets of code that are a good idea to include on both windows and mac builds that help start things up and close things down etc?
Cheers
Bidge
Re: Saving a text file
Posted: Thu Jul 13, 2017 12:33 pm
by jmburnod
Hi Bidge,
Are there any hints or tips when it comes to building a standalone exe
Yes,
1. When you compile a standalone, you can't change it.
It remains like you compiled it.
2. You can save data to external files (stacks also) specialfolderpath("documents") is probabily the best place.
You may create a subfolder for your app only.
3. You can import data from these files in your standalone
(Apple store doesn't agree import of stacks) for images (paint format or filename), text, sounds etc...)
All the best
Jean-Marc
Re: Saving a text file
Posted: Thu Jul 13, 2017 12:50 pm
by bidgeeman
Hi Jean-Marc.
I remember some years ago when I bought Runrev V3.5 and was looking at compiling a stack to an exe, I struck some problems with the stacks still remaining in memory after quitting a standalone on Windows. I imagine things are a bit different today and was just wondering if any of those types of issues still exist?
Cheers
Bidge
Re: Saving a text file
Posted: Thu Jul 13, 2017 2:02 pm
by Klaus
Hi David,
bidgeeman wrote:I remember some years ago when I bought Runrev V3.5 and was looking at compiling a stack to an exe, I struck some problems with the stacks still remaining in memory after quitting a standalone on Windows. I imagine things are a bit different today and was just wondering if any of those types of issues still exist?
that was almost 6 versions ago, so I think these issiues have been ironed out in hte meantime, and new invconvenineces have been intrduced since then!
Just kidding.
In ANY case, please run your app on any target platform, I remember there may be slight differences between Mac and Win when it comes to text and fonts.
Preferences (of your and any other app) are exspected to be saved in special folders, in specialfolderpath("documents") it is likely that the user will wreck it!
Mac ->
specialfolderpath("preferences")
Windows ->
specialfolderpath(26) = for current user only
specialfolderpath(35) = for ALL users
Not sure if this still applies to Win 10, so please do a quick check in the message box on Windows:
put specialfolderpath(26)
Best
Klaus
Re: Saving a text file
Posted: Thu Jul 13, 2017 4:01 pm
by bogs
Klaus wrote:<sic>...In ANY case, please run your app on any target platform, I remember there may be slight differences between Mac and Win when it comes to text and fonts...<sic>
Slight difference indeed, here is a good read on the subject
"Font rendering philosophies of windows and mac os x"
Re: Saving a text file
Posted: Fri Jul 14, 2017 2:03 am
by bidgeeman
Hi.(SOLVED)
I a managed to get it to work
Can someone please tell me what is going wrong here? I am using Klaus's snapshot code example to take a snapshot of one card and put it into an image area on another card but for some reason the "rect" is giving me a "screenshot" of the top corner of my screen and partial stack poking through the "Livecode" interface?
How do I export just the image area of the stack only and not a screenshot that could include things that may be placed over the top of the card?
(AMMENDED)
Code: Select all
export snapshot from cd "ImageAreaCard" of stack "ImageArea" to image "W1" of stack "ToPrint"
Thanks again.
Bidge