Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Dec 14, 2017 9:44 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 5:36 am 
Offline

Joined: Sat Dec 30, 2006 6:52 pm
Posts: 130
Location: New York City
When I want to save a file I've updated using one of my programs a button press calls the code here:

dim f as folderitem
dim i as integer
dim stream as binarystream
dim theStoringFolder as String
theStoringFolder = "/home/Documents/"
f=getsaveFolderItem("", theStoringFolder + "myFile")
if f<> nil then
stream=f.createbinaryfile("myfiletype")
stream.WriteLong myListBox.ListCount
for i=0 to myListBox.listcount-1
stream.writePString myListBox.list(i)
next
stream.close
end if


I then have to press a key given this choice:
[Save] [Cancel]

And then I have to press another key given this choice:
'/home/Documents/myFile' already exists.
Overwrite it?
[Yes] [No]


Is there a way to eliminate these 2 key presses by adding instructions to my (above) code?


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 12:15 pm 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
instead of

f=getsaveFolderItem("", theStoringFolder + "myFile")

use

f=getFolderItem("", theStoringFolder + "myFile")


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 12:43 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
To eliminate this step,
Quote:
And then I have to press another key given this choice:
'/home/Documents/myFile' already exists.
Overwrite it?
[Yes] [No]

Do...
stream=binaryStream.Create(f, True)
//You should be using this form anyway


But be aware that your previously existing file will always be overwritten.
YOu should also check for
stream <> Nil
before proceeding to use the stream object.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 12:56 pm 
Offline

Joined: Sat Dec 30, 2006 6:52 pm
Posts: 130
Location: New York City
kermit wrote:
instead of

f=getsaveFolderItem("", theStoringFolder + "myFile")

use

f=getFolderItem("", theStoringFolder + "myFile")
Is more needed here than a simple swap of names? Just making the change you suggested results in the following error msg.
Parameters are not compatible with this function
f=getFolderItem("",theStoringFolder + "myFile")


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 1:07 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
Eliminate that first argument passed.
f=getFolderItem(theStoringFolder + "myFile")

But, adding the caveat that there are many things which can go wrong with (theStoringFolder + "myFile")
Firstly, I don't know exactly what "thestoringFolder" contains, but it should proibably be
theStoringFolder.Child("myFile")
Secondly, if "theStoringFolder" is a complicated path, then it can fail at many levels.
Use .Child to work down through your folder heirarchy checking <> Nil and .Exists at each level.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 1:13 pm 
Offline

Joined: Sat Dec 30, 2006 6:52 pm
Posts: 130
Location: New York City
classone wrote:
To eliminate this step,
Quote:
And then I have to press another key given this choice:
'/home/Documents/myFile' already exists.
Overwrite it?
[Yes] [No]

Do...
stream=binaryStream.Create(f, True)
//You should be using this form anyway


But be aware that your previously existing file will always be overwritten.
YOu should also check for
stream <> Nil
before proceeding to use the stream object.
I changed my "stream=..." line to the one you suggested. The program runs exactly as before and still requires the 2 "extra" presses I'm trying to eliminate. Thanks for your help - is there something else I am leaving out?


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 1:34 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
In short, yes, there's something you are doing wrong.
Post your new, complete code and I'll have a look later this evening.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 1:43 pm 
Offline

Joined: Sat Dec 30, 2006 6:52 pm
Posts: 130
Location: New York City
classone wrote:
In short, yes, there's something you are doing wrong.
Post your new, complete code and I'll have a look later this evening.

Here are the "actual" lines. I had simplified them in my original post...

dim f as folderitem
dim i as integer
dim stream as binarystream
dim theStoringFolder as String
theStoringFolder = "/home/paulie/Documents/"
f=getsaveFolderItem("", theStoringFolder + "1WeightLst")
if f<> nil then
stream=binaryStream.Create(f, True)
stream.WriteLong myListBox.ListCount
for i=0 to myListBox.listcount-1
stream.writePString myListBox.list(i)
next
stream.close
end if
quit


Thanks for taking the time to offer your help!
Paul


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 1:51 pm 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
getsaveFolderItem...

displays a dialog that asks the user what file name to use, and allows them to change it.
It also carries logic to ask those questions.

Use getFolderItem() instead.

It only wants one parameter: the name of the output file.
f=getFolderItem(theStoringFolder + "myFile")


But since it is documents, the better approach is:

f = specialfolder.documents.child("myfile")


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 1:52 pm 
Offline
User avatar

Joined: Thu Jul 27, 2006 6:31 pm
Posts: 1698
Location: Monterey, CA
dim theStoringFolder as String
theStoringFolder = "/home/paulie/Documents/"
f=getsaveFolderItem("", theStoringFolder + "1WeightLst")


Don't hard codes paths like this. If you're accessing a common location like this then use:

dim f as FolderItem
f=SpecialFolder.Documents.child("1WeightLst")

_________________
ImagePlay Effects Library (40+ image effects in one open source module. No plugins, no dependencies, no restrictions.)
http://imageplay.sourceforge.net/


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 6:23 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
Please pardon if this sounds a bit short, but kermit told you about 6 posts ago to use GetFolderItem instead of getSaveFolderItem. You ignored his advice and then wonder why you're still getting the same results.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 7:12 pm 
Offline

Joined: Sat Dec 30, 2006 6:52 pm
Posts: 130
Location: New York City
classone wrote:
Please pardon if this sounds a bit short, but kermit told you about 6 posts ago to use GetFolderItem instead of getSaveFolderItem. You ignored his advice and then wonder why you're still getting the same results.
I appreciate your help, but look again (about 8 posts above). I DID try kermit's suggestion and reported my results. Do you now understand why I am wondering why etc... ? Sorry if this sounds petulant, but I took the bait.


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Sun Jun 02, 2013 7:46 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
If I correctly understand your needs, this code should do what you want. Please try it and let me know your results.
dim f As FolderItem = SpecialFolder.Documents
dim stream As BinaryStream

if f = Nil or not f.Exists Then
MsgBox "There is no documents folder."
Return
end if

f = f.Child("1WeightLst")
if f <> Nil Then
stream = BinaryStream.Create(f, True) //creates a file named '1WeightLst' and overwrites any existing file
if stream <> nil Then
dim u As Integer = myListBox.listCount-1
for i As Integer = 0 to u
stream.WritePString myListBox.list(i)
Next
stream.Close
end if
end if

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Mon Jun 03, 2013 5:15 am 
Offline

Joined: Sat Dec 30, 2006 6:52 pm
Posts: 130
Location: New York City
classone - I tried your code (thank you for doing this for me!) but it triggers the error msg. "There is no documents folder."


Top
 Profile  
Reply with quote  
 Post subject: Re: Eliminating "extra" steps in saving a file.
PostPosted: Mon Jun 03, 2013 6:55 am 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
Then add the step to create that folder within the conditional.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group