Page 2 of 3

Re: Writing to a file

Posted: Tue Jun 21, 2016 8:02 pm
by mwieder
Ah. OK. In that case you have two choices:

1. Make newSFP a global variable
2. Pass newSFP as a parameter to the function that deletes the folder.

The first option is easier to implement, although a little quirky in xtalk, but is best avoided in general because of scope issues.
The second one requires a bit of refactoring of your code, so it's more involved, but is a better general-purpose solution.

one possible Solution 1:
put this line into the mouseUp handlers of both buttons:

Code: Select all

global newSFP
a better Solution 1:
in button "btnDelete"
add this line before the "delete Folder" line:

Code: Select all

put field "Field2" into newSFP
one possible Solution 2:
in the card script:

Code: Select all

local sNewSFP -- this is now a script-local variable, available to all card script handlers
command deleteThisFolder
  delete folder sNewSFP
end deleteThisFolder

command storeThisFolder pFolder
  put pFolder into sNewSFP
end storeThisFolder
in button "btnDelete":

Code: Select all

deleteThisFolder
in button "btnMakeDirectory":
put this line after "put newSFP into field Field2":

Code: Select all

storeThisFolder newSFP
Or experiment with other variations on the above possibilities.

Re: Writing to a file

Posted: Tue Jun 28, 2016 7:32 am
by RossG
Next step: to open the file just created with

put field tProgression into URL ("file:" & newSFP & "/" & fName)

Tried all the combinations I can think of but no luck so far.

Suggestions appreciated.

Win XP (for ever).

Re: Writing to a file

Posted: Tue Jun 28, 2016 8:12 am
by [-hh]

Re: Writing to a file

Posted: Wed Jun 29, 2016 4:11 am
by rumplestiltskin
Maybe I'm missing something. Using the example in the first link I am trying this script in a button:

Code: Select all

   put field "field1" into URL "file:/MacHD/Users/blevine/Desktop/myfile.txt"
   answer the result
The result is "can't open file". I don't see anything in the lesson about having to open the file first before writing. There is already a file named "myfile.txt" I created in that location using TextEdit.

Thanks,
Barry

Re: Writing to a file

Posted: Wed Jun 29, 2016 4:23 am
by RossG
Should have made it clear that I want the file
to open in Notepad or whatever is set as the
default for .txt files.

Re: Writing to a file

Posted: Wed Jun 29, 2016 9:44 am
by AxWald
Hi,
RossG wrote:Should have made it clear that I want the file to open in Notepad or whatever is set as the default for .txt files.

Code: Select all

get shell("MacHD/Users/blevine/Desktop/myfile.txt")
should do the trick ...

Have fun!

Re: Writing to a file

Posted: Wed Jun 29, 2016 10:09 am
by [-hh]
Here works also, on Mac/Win/Linux

launch document <path>

where <path> is a directoryPath or filePath that will be
opened using the current system's launch services.

There is also "launch URL <theURL>" if you prefer URL-syntax.
If using Windows, you could also have a look at "relaunch" in the dictionary.

p.s On MacOS, I use to precede disk names with "/Volumes/".
For example
launch document "/Volumes/Macintosh HD"
opens "/" with application "Finder" (if 'Macintosh HD' is your only internal disk).
Works also if the directory path has a trailing slash.

Re: Writing to a file

Posted: Wed Jun 29, 2016 5:56 pm
by jacque
The best way to write to the desktop is to let the engine determine the file path for you. Use specialFolderPath to get the correct path on any OS.

Code: Select all

put field "field1" into URL (specialFolderPath("desktop") & "/myfile.txt") 
SpecialFolderPath provides locations for several other commonly used locations also.

Re: Writing to a file

Posted: Wed Jun 29, 2016 8:31 pm
by Klaus
Erm, better add FILE:
jacque wrote:

Code: Select all

put field "field1" into URL ("FILE:" & specialFolderPath("desktop") & "/myfile.txt") 
8)

Re: Writing to a file

Posted: Wed Jun 29, 2016 9:00 pm
by mwieder
LOL.
Better than best, eh?

Re: Writing to a file

Posted: Wed Jun 29, 2016 10:46 pm
by Klaus
mwieder wrote:LOL.
Better than best, eh?
Hey, my name is Major, what do you exspect? :D

Re: Writing to a file

Posted: Thu Jun 30, 2016 4:25 pm
by jacque
Oops. I've been bested.

Was writing on my tablet and to save time I copied the original and edited it. Incorrectly.

Re: Writing to a file

Posted: Thu Jun 30, 2016 9:07 pm
by mwieder
Well, Klaus has over 8500 posts to his credit.
He has to be right once in a while. :P

Re: Writing to a file

Posted: Fri Jul 01, 2016 3:39 am
by RossG
Progression Designer v1.3.zip
(4.32 KiB) Downloaded 313 times
Thanks for your efforts gentlemen but
I'm still struggling with this one.

So attached is the stack in question.

Put some numbers into the four fields.
I suggest 4,11,35 and 10.

Click the "Calculate Progression" button.
Click the "Save as..."
Label will change to "Open...."
I want this button to open the file just saved in Notepad
or the default prog. for .txt files.

The "HereYouAre" field is temporary for testing.

BTW I programmed this some years ago and now have no
idea how or why it works but it does...

Re: Writing to a file

Posted: Fri Jul 01, 2016 6:01 am
by mwieder
First of all, some code style tips:
Press the tab key while in the editor and it will automatically format the text nicely for you.

Next, you'll stay out of trouble a bit more if you put literal values in quotes.
Took me a bit to figure out that tArray and tProgression weren't local variables.

You have a line

Code: Select all

put 0 into cArray[x.1]
and I don't know what you intend by that. Do you mean x,1 instead of x.1?

(almost at the end) it's bad form to name a control as a keyword. Button "Save" is bound to cause trouble sometime.

Lastly, if you want to open the same file you save, you're missing a "/" delimiter between newSFP and fName in three lines.
Cheers