Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Jul 27, 2017 5:45 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 11:03 am 
Offline

Joined: Tue May 10, 2011 7:20 am
Posts: 15
Ok so I have my experiment built and running apart from it not outputting the data file.

In my desktop applications I have always used:

OutPutFile = GetFolderItem("Output" + session.subject + ".txt")
OPF = session.OutPutFile.CreateTextFile

And then written to it using:

OPF.WriteLine "Subject" + "," + "Age" + "," + "Gender" + "," + "Condition" + "," + "ChoiceNumber" +"," +"PickedOption" + "," + "Outcome Picked" +"," + "Outcome NP" + ","+"Sides"


However, I cannot get it to make such a file in this web application (at least its not saving it in the folder its run from like it would with a Desktop Application). Any solutions for this? Simply put I need each person who runs through my application to have their responses recorded and saved on the server in a csv text file so I can later access, download, and analyze them.


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 11:41 am 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
First, a quick tip, Session is a function, so every time you call it you're running a function. To save time use this:
Dim Session As Session = Session


Otherwise, I'm not sure what issue you're having. Can you please elaborate on what you've tried? Working with files on the server is the exact same as a desktop application. Use a FolderItem, a TextOutputStream, and you're good to go. This would make a file in the same folder as the Web Application.
Dim File As FolderItem = GetFolderItem("MyFile.txt")
Dim Output As TextOutputStream.Create(File)
Output.Write "Hello World!"


(Note: I'm not doing important file checking to make sure the directory is writeable, but am just showing that it's plain and simple.)

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 11:51 am 
Offline

Joined: Tue May 10, 2011 7:20 am
Posts: 15
Hey thanks for your reply. The session is in there as i have that defined on the level of session as it was breaking it if I defined it anywhere else (this is not reflected through the code above as I removed it for simplicity here).

Yeah that's what I thought but its not working. Maybe its the permissions, how would I set those? Sorry if this is simple stuff but I am not a programmer just a psychologist forced to program to get data ;)


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 12:15 pm 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
rjwrig wrote:
Yeah that's what I thought but its not working. Maybe its the permissions, how would I set those? Sorry if this is simple stuff but I am not a programmer just a psychologist forced to program to get data

No worries. ;)

To check put this somewhere:
Dim Folder As FolderItem = GetFolderItem("").Parent
If Folder.IsWriteable Then
MsgBox "Files can be written to this directory"
Else
MsgBox "This directory is read-only"
End If


What OS are you deploying the Web Application on?

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 12:16 pm 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
Actually, rather than that, are you getting a TextOutputStream.WriteError?

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 12:36 pm 
Offline

Joined: Tue May 10, 2011 7:20 am
Posts: 15
Hey so I put that in and I got the "Files can be written to this directory" message. I am testing on system running Windows Vista.

It is weird as it runs all just nice and fine with no errors but in the end there is no text file anywhere I can find.


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 12:43 pm 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
Please copy the exact code you're using so I can make sure there's not something missing. It's difficult to abstractly figure out a simple bug.

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 1:09 pm 
Offline

Joined: Tue May 10, 2011 7:20 am
Posts: 15
OutPutFile = GetFolderItem("EDATA" + session.subject + ".txt")
OPF = OutPutFile.CreateTextFile

OPF.WriteLine "Subject" + "," + "Age" + "," + "Gender" + "," + "Condition" + "," + "ChoiceNumber" +"," +"PickedOption" + "," + "Outcome Picked" +"," + "Outcome NP" + ","+"Sides"


This is my exact code. I have OutPutFile and OPF already defined as properties (doesn't seem to make a difference if I create them on the fly).

The program runs but crashes on that first WriteLine command.


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 3:31 pm 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
You're using a deprecated function, try this:

OutPutFile = GetFolderItem("EDATA" + session.subject + ".txt")
OPF = TextOutputStream.Create(OutPutFile)

OPF.WriteLine ("Subject" + "," + "Age" + "," + "Gender" + "," + "Condition" + "," + "ChoiceNumber" +"," +"PickedOption" + "," + "Outcome Picked" +"," + "Outcome NP" + ","+"Sides")


Otherwise, what's the error you get when it crashes?

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 4:19 pm 
Offline

Joined: Tue May 10, 2011 7:20 am
Posts: 15
Hi Jason so I tried that and it stops at: OPF = TextOutputStream.Create(OutPutFile)

When it stops there is no error message. It just freezes the browser window and highlights the line of code in grey.

I have version Real Studio 1.1 not 1.2 if that makes a difference.


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 4:57 pm 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
If you look in the bottom-left corner of the IDE, you'll see some text that describes what kind of exception you're getting on that line. Also, you can look in the pane on the right to see if OutPutFile is nil at that point. If it is, you're getting a NilObjectException from trying to pass a nil object to the TextOutputStream.Create function.

Also, I just remembered this: When you run a program from the IDE, it creates a temporary directory in the same directory as your project file. If you use GetFolderItem and create files in the same directory as your application, then during debug the files will be deleted once you quit running from the IDE. For this reason, I'll often do this:

#if DebugBuild
OutPutFile = SpecialFolder.Desktop.Child("MyFile.txt")
#else
OutPutFile = GetFolderItem("MyFile.txt")
#endif


That places the file on my desktop when I'm debugging, and in the application folder any other time.

Hope this helps! :)

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Thu May 23, 2013 6:15 pm 
Offline

Joined: Tue May 10, 2011 7:20 am
Posts: 15
Yup that's it getting a nil object exception on the OPF property. When I run analyze it says my code is depreciated as you have said but then it breaks when I replace it stopping where I had said saying IO error with the code being 32 which I guess is:

ERROR_SHARING_VIOLATION
32 (0x20)
The process cannot access the file because it is being used by another process.

So it looks like its being used when I try to use it somehow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Fri May 24, 2013 11:20 am 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
Ah, are you creating this file, or modifying a pre-existing one?

Sorry, I'm starting to grasp at straws a bit. Not being familiar with your application, it's hard to know what I don't know. ;)

If you are creating a file from scratch, it sounds like a programming error or some error with where you're placing the file. Maybe it requires administrative privileges? Have you tried changing the name to something simple and writing it to the desktop? Start simplifying your code to try and isolate the issue.

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: Generate and Save Text File - On host/server
PostPosted: Fri May 24, 2013 3:59 pm 
Offline

Joined: Tue May 10, 2011 7:20 am
Posts: 15
Hey thanks yes I am wanting to make new files each time so in the end I would have a separate text file for each subject who goes through the experiment.

I will look into trying to write to a specific directory, right now I am just running it in debug mode and the folder is on the desktop which usually works just fine if I am making a desktop application so that's why its puzzling me as I assumed they would run about the same.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group