Can't manage files fairly

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

rjuan
Posts: 12
Joined: Fri May 03, 2013 5:03 pm

Can't manage files fairly

Post by rjuan » Fri May 03, 2013 5:27 pm

Bonjour,
I have a poor english, so I apologize if I'm a bit hard to understand.

I try to set up a standalone app dealing with bank accounts and stuff like this.
On opening the stack I want to get the contents of text files : comptes.txt, ventilation.txt, lignes.txt, detailscomptes.txt; those files are beside the app.
Here is the code :

Code: Select all

on lectureFichiers
   -- on lit les fichiers de données
   open file "comptes.txt"
   read from file "comptes.txt" until EOF
   put it into field id 1214 of card "init"
   close file "comptes.txt"
   open file "detailscomptes.txt"
   read from file "detailscomptes.txt" until EOF
   put it into field "listecomptes" of card "paramètres"
   close file "detailscomptes.txt"
   open file "ventilation.txt"
   read from file "ventilation.txt" until EOF
   put it into field "ventilation" of card "paramètres"
   close file "ventilation.txt"
    open file "lignes.txt"
   read from file "lignes.txt" until EOF
   put it into field "lignes" of card "paramètres"
   close file "lignes.txt"
  end lectureFichiers
I don't understand why I don't have any error but the files are not imported.
If I debug step by step, the "it" variable stay empty after a read from file command ?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Can't manage files fairly

Post by dunbarx » Fri May 03, 2013 5:40 pm

Hmmm.

Your code looks OK. Is it possible that the file is in a place where it cannot be found? Try to substitute a full pathName to the file and test:

Code: Select all

open file "/users/yourUserName/desktop/comptes.txt" 
This assumes the file is on the desktop, of course.

Craig Newman

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: Can't manage files fairly

Post by Newbie4 » Fri May 03, 2013 6:04 pm

Look at the result after each command.
e.g. instead of
"Put it..."
use
"Put the result..."

or even better try the commands (open, read, etc in the message box OT see what the problem is
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

rjuan
Posts: 12
Joined: Fri May 03, 2013 5:03 pm

Re: Can't manage files fairly

Post by rjuan » Fri May 03, 2013 6:54 pm

Sorry, what does mean "OT"
or even better try the commands (open, read, etc in the message box OT see what the problem is
Thank you any way for your responses.

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: Can't manage files fairly

Post by Newbie4 » Fri May 03, 2013 8:22 pm

rjuan wrote:Sorry, what does mean "OT"
or even better try the commands (open, read, etc in the message box OT see what the problem is
Thank you any way for your responses.
I apologize. That was a typing error. I meant to type the word "to" but it ended up "OT"

I was trying to get you to try out the commands in the message box...

If you click on the "Message Box" icon on the LiveCode Edit Bar, it opens up a window where you can type commands to try them out. I was suggesting that you try your Open command there and see what it reports back to you.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Can't manage files fairly

Post by Simon » Fri May 03, 2013 9:34 pm

Hi rjuan,
When I started with LC I used "Open" for reading files because it made sense to me but there is an easier way:

Code: Select all

on lectureFichiers
   --Setting the default folder to the same folder as your stack
   set the itemDelimiter to slash
   get the effective filename of this stack
   set the defaultFolder to item 1 to -2 of it
   -- End setting folder
   put url("file:comptes.txt") into field id 1214 of card "init" 
   put url("file:detailscomptes.txt") into field "listecomptes" of card "paramètres"
   put url("file:ventilation.txt") into field "ventilation" of card "paramètres"
   put url("file:lignes.txt") into field "lignes" of card "paramètres"
end lectureFichiers
You can see how much cleaner that is.
If you debug that and the fields don't fill then there is something wrong with where you texts files are. Try:

Code: Select all

 -- End setting folder
put the files
If you don't see your text files listed then they are somewhere else.

If you put the defaultFolder into a variable you can start using sub folders from the stack e.g.

Code: Select all

put field "lignes" into url ("file:" & myFolder & "/Documents/lignes.txt") --Make sure there is a Documents folder first
That will keep the stack folder clean.

I think that "Open" would only be used to directly manipulate a files content, your use looks correct and it should have worked if the defaultFolder was set correctly.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Can't manage files fairly

Post by dave_probertGA6e24 » Fri May 03, 2013 10:39 pm

I'm guessing from your use of the word "App" instead of "exe" that you are using a Mac. If so then remember that the files that sit 'next' to the App are actually a couple of folders Above the executable file - unlike on Windows where they are actually next to the exe.

App's on Macs are actually folders with subfolders - one of which contains the executable. If you 'right-click' on an App (on the Mac) then the menu that appears should give you the option of "Show Package Contents" (or the equivalent in your language) - that will allow you to see where the actual executable file is relative to the data files.

I use code like this to get the correct path to files sitting next to the App/Exe:

Code: Select all

if the platform is "MacOS" then
  put -4 into tLevels
else
  put -2 into tLevels
end if
set the itemdel to slash
put item 1 to tLevels of the effective filename of this stack into myPath
That usually works.

Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Can't manage files fairly

Post by Simon » Fri May 03, 2013 11:12 pm

Wow Dave,
Are you saying that after all these years

Code: Select all

set the itemDelimiter to slash
   get the effective filename of this stack
   set the defaultFolder to item 1 to -2 of it
is incorrect? Or is it only correct when working in the IDE?
Admittedly I use something similar to your script for my standalones.
But, Dang! it's in the dictionary that way. :shock:

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

rjuan
Posts: 12
Joined: Fri May 03, 2013 5:03 pm

Re: Can't manage files fairly

Post by rjuan » Sat May 04, 2013 8:45 am

Thank you for all those answers wich help me a lot.
The trouble now is that I did not understand how standalones applications manage those file:
With your help I could read the files I need on openstack and then write the modified textfiles to there proper place on closestack BUT this in the UI of livecode, when I tried on the saved as standalone, nothing happen. It's just like no data are read, the files wich must be read on openstack aren't.

I've read on the documentation that standalones are read only so how can I distribute my app on a windows PC as a standalone ?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Can't manage files fairly

Post by jmburnod » Sat May 04, 2013 10:06 am

Hi juan,
Yes. standalone is read only, then You have to read your file and put its content in a variable or custom property.
The script below builds the folderpath containing the stack or the standalone for Windows or OSX.

Code: Select all

   put the itemdel into OID
   put the effective filename of this stack into tPath
   put the environment into pEnv
   set the itemDelimiter to slash
   if the platform = "MacOS" then 
      if pEnv = "standalone application" then
         put - 4 into tLevel
      end if
      if pEnv = "development" then
         put - 2 into tLevel
      end if
   else
      put - 2 into tLevel
   end if
   put item 1 to tLevel of tPath into tFolderAppPath
   set the itemdel to OID
   put tFolderAppPath

Best regards
Jean-Marc
https://alternatic.ch

rjuan
Posts: 12
Joined: Fri May 03, 2013 5:03 pm

Re: Can't manage files fairly

Post by rjuan » Sat May 04, 2013 5:54 pm

Thank you for that, I'm going to work on it.

I was wondering then if a large amount of lines (let say more than two or three thousands) could lead to trouble if used in a variable or property ?
Is there a limit ?

Bonjour à mes amis suisses, j'ai appris à lire et écrire près de Lucens, à Combremont le Petit !
Cordialement, Richard.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Can't manage files fairly

Post by jmburnod » Sat May 04, 2013 7:22 pm

Hi rjuan,
Is there a limit ?
There is a chapter about limits in the release notes (help menu)
Best regards
Jean-Marc
https://alternatic.ch

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Can't manage files fairly

Post by Simon » Sun May 05, 2013 3:37 am

A variable can hold 4 GB of data
A field can hold 4 GB of data but the maximum length of a line in a field 65,536 characters storage. No more than 32,786 pixels wide for display

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

rjuan
Posts: 12
Joined: Fri May 03, 2013 5:03 pm

Re: Can't manage files fairly

Post by rjuan » Sun May 05, 2013 8:59 am

Good, I'm progressing.

Last thing I would like to know is why my texte with accent :
...
05 +Intérêts
06 ...

appear in the field like : 05 +Intérêts

I know it's a matter of coding the text. Mine is in UTF - 8, I thought that will be ok for a mac and a winPC , so what is the trouble ?
I've look around to try to fix but I couldn't.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Can't manage files fairly

Post by jmburnod » Sun May 05, 2013 9:08 am

Hi rjuan,
Sorry I have to move. No time for accent mistake.
You can also use a file to store the results for each student and read it at preopenstack.
For exemple one file per student, one line per card "namecard,answer1,answer2, etc...
At the same time you do a "results report" which should be useful.
Best
Jean-Marc
https://alternatic.ch

Post Reply