1. Open command in wxEuphoria
- Posted by Jesse Adkins <Tassadar29 at lycos.com> Jun 28, 2006
- 691 views
- Last edited Jun 29, 2006
Well, i've been trying to do the same thing as before. I've realized that the reason for most of my problems before was because I was copying code that had been custom made and other such things. I finally cut down the code this which I think is about right
procedure load_file( sequence file ) object in integer fn fn = open(file,"r") in = gets(fn) while sequence(in) do in = in[1..length(in)-1] load_file( in ) in = gets( fn ) end while close(fn) end procedure procedure on_open( atom this, atom event_type, atom id, atom event ) sequence file file = file_selector( Starter, "Select a project or file to open", {"","","", "WaXy Documents|*.WaX|All Files (*.*)|*.*;*"},wxOPEN) load_file(file) end procedure
Once again, I took this off of the wxIDE. This time, I get a much different error whenever I try to open a file (any file)
bad file number (-1)
The .err file goes way past that but I think it's all because of the bad file number. I've tried everything that I can think of to try and fix it and nothing works. Can anyone help me fix this problem? Any and all help appreciated.
2. Re: Open command in wxEuphoria
- Posted by ChrisBurch2 <crylex at freeuk.co.uk> Jun 28, 2006
- 606 views
- Last edited Jun 29, 2006
Hi fn = open(file, "r"), is returning -1 for fn (hence the bad file number - its an error indicator This means open() can't find the file this means that the file sequence being passed to open_file is nor correct put a puts(1, file) in the, at the beginning of open_file(), see whats being passed to it. Chris
3. Re: Open command in wxEuphoria
- Posted by Jesse Adkins <Tassadar29 at lycos.com> Jun 29, 2006
- 627 views
Hi fn = open(file, "r"), is returning -1 for fn (hence the bad file number - its an error indicator This means open() can't find the file this means that the file sequence being passed to open_file is nor correct put a puts(1, file) in the, at the beginning of open_file(), see whats being passed to it. Chris When I do that, it stops me before the file_selector comes up with a new message variable file has not been assigned a value. I took a look in the .err file and this is what it told me in a nutshell... file = {67'C',58':',92'\',68'D',111'o',99'c',117'u',109'm',101'e',110'n', 116't',115's',32' ',97'a',110'n',100'd',32' ',...and so on. It's trying to give the file path by the looks of it. (C:\Documents and...) in = <no value> fn = -1
4. Re: Open command in wxEuphoria
- Posted by don cole <doncole at pacbell.net> Jun 29, 2006
- 597 views
Jesse Adkins wrote: > > Well, i've been trying to do the same thing as before. I've realized that the > reason for most of my problems before was because I was copying code that > had been custom made and other such things. > > I finally cut down the code this which I think is about right > }}} <eucode> > procedure load_file( sequence file ) > object in > integer fn > fn = open(file,"r") > in = gets(fn) > while sequence(in) do > in = in[1..length(in)-1] > load_file( in ) > in = gets( fn ) > end while > close(fn) > end procedure > procedure on_open( atom this, atom event_type, atom id, atom event ) > sequence file Hello Jesse, Right here put file={} and see what happens. Don Cole Bonds > Ruth. Giants in second to last place. > file = file_selector( Starter, "Select a project or file to open", > {"","","", > "WaXy Documents|*.WaX|All Files (*.*)|*.*;*"},wxOPEN) > load_file(file) > end procedure > </eucode> {{{ > Once again, I took this off of the wxIDE. > > This time, I get a much different error whenever I try to open a file (any > file) > > }}} <eucode> bad file number (-1) </eucode> {{{ > > The .err file goes way past that but I think it's all because of the bad file > number. > > I've tried everything that I can think of to try and fix it and nothing works. > Can anyone help me fix this problem? > > Any and all help appreciated. Don Cole
5. Re: Open command in wxEuphoria
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 29, 2006
- 616 views
On Wed, 28 Jun 2006 14:20:35 -0700, Jesse Adkins <guest at RapidEuphoria.com> wrote: >}}} <eucode> >procedure load_file( sequence file ) > object in > integer fn > fn = open(file,"r") > in = gets(fn) > while sequence(in) do > in = in[1..length(in)-1] > load_file( in ) ></eucode> {{{ That is pretty much an infinite loop. At the top of the ex.err you should see fn=-1 and file=???, which will be something other than a filename, which it is trying to open, and it should be obvious from whatever ??? is what went wrong, or a file is missing/misspelt. The ex.err is your friend and usually indicates where the error lies in just the first few lines. Do not be put off just because it is a bit long. Instead when looking at the code which has gone wrong, and you wonder 'so what is the value of filename then?', go to the ex.err and use the find function, easy. I assume that file_selector returns a file list in the form {"C:\MyStuff\Project1.WaX"} so start with (untested!):
file=file_selector(...) for i=1 to length(file) do load_project(file[i]) end for
(or perhaps just load_project(file[1]) if no multi-select) Assuming that each .WaX file contains a list of other files to load, some of which may also be projects:
procedure load_project(sequence filename) integer fn object in -- start with a quick sanity check if match(".WaX",filename)!=length(filename)-3 then puts(1,"not a project!\n") ?9/0 end if fn= open(filename,"r") while 1 do in = gets(fn) if atom(in) then exit end if in = in[1..length(in)-1] if match(".WaX",in)=length(in)-3 then -- it's a sub-project load_project(in) else -- it's something else load_file_or_something_else(in) end if end while end procedure
(Again, if a .Wax cannot contain other .WaX files, the above is a bit over-complicated.) HTH, Pete
6. Re: Open command in wxEuphoria
- Posted by Jesse Adkins <Tassadar29 at lycos.com> Jun 29, 2006
- 593 views
- Last edited Jun 30, 2006
procedure load_project(sequence filename) integer fn object in -- start with a quick sanity check if match(".WaX",filename)!=length(filename)-3 then puts(1,"not a project!\n") ?9/0 end if fn= open(filename,"r") while 1 do in = gets(fn) if atom(in) then exit end if in = in[1..length(in)-1] if match(".WaX",in)=length(in)-3 then -- it's a sub-project load_project(in) else -- it's something else load_file_or_something_else(in) end if end while end procedure
The .WaX thing was what I was planning on calling the files later. The second part of it checks by any file and still gives the same -1 error so, I don't think it's entirely the fault of the extension address. Anyway, I just put in that code and modified the other half to fit it and now it just blinks an error message at me. I took that ?9/0 out since that gave a division by zero error. I changed the .WaX to something more common (.rtf). When I open an .rtf file with it looking for .rtf, it goes toward the else instead of just opening.
7. Re: Open command in wxEuphoria
- Posted by ChrisBurch2 <crylex at freeuk.co.uk> Jun 29, 2006
- 618 views
- Last edited Jun 30, 2006
Hi Debugging code : what are you expecting vs what are you getting 1. The filename should be a valid path and filename. test this
procedure load_project(sequence filename) integer fn object in puts(1, filename) --do you get the correct output here -- start with a quick sanity check if match(".WaX",filename)!=length(filename)-3 then puts(1,"not a project!\n") ?9/0 end if fn= open(filename,"r") while 1 do in = gets(fn) if atom(in) then exit end if in = in[1..length(in)-1] if match(".WaX",in)=length(in)-3 then -- it's a sub-project load_project(in) else -- it's something else load_file_or_something_else(in) end if end while end procedure
2. the filename is not being opened properly try this
procedure load_project(sequence filename) integer fn object in filename = "c:\\projects\\test.WaX" --or a correct path to a file, or what SHOULD have been passed to the function --filename = "test.WaX" --make sure the file exists in the folder it should be in -- start with a quick sanity check if match(".WaX",filename)!=length(filename)-3 then puts(1,"not a project!\n") ?9/0 end if fn= open(filename,"r") while 1 do in = gets(fn) if atom(in) then exit end if in = in[1..length(in)-1] if match(".WaX",in)=length(in)-3 then -- it's a sub-project load_project(in) else -- it's something else load_file_or_something_else(in) end if end while end procedure
Chris
8. Re: Open command in wxEuphoria
- Posted by Jesse Adkins <Tassadar29 at lycos.com> Jun 29, 2006
- 579 views
- Last edited Jun 30, 2006
I actually did a little modification of my own just now.
procedure load_project(sequence filename) integer fn object in -- start with a quick sanity check if match(".rtf",filename)!=length(filename)-3 then puts(1,"not a project!\n") end if fn= open(filename,"r") while 1 do in = gets(fn) append_text(M,in) end while end procedure
(M is my TextCtrl) The code i've got will open the file and put all of the text into the TextCtrl, including the markups (the /t and /par stuff but that just needs a filter). However, there is another problem that arises. I don't know how to stop append_text from getting the text in the file so, it eventually tries to go past what is in the file, generating a new error... type_check failure, val is -1 I don't know how to stop the code from hitting the bottom or to check for -1. I've tried to set val as something and then an if statement to make it stop when it hits -1 but it passes it up.
9. Re: Open command in wxEuphoria
- Posted by don cole <doncole at pacbell.net> Jun 29, 2006
- 590 views
- Last edited Jun 30, 2006
Jesse Adkins wrote: > > I actually did a little modification of my own just now. > }}} <eucode> > procedure load_project(sequence filename) > integer fn > object in > > -- start with a quick sanity check > if match(".rtf",filename)!=length(filename)-3 then > puts(1,"not a project!\n") > end if > fn= open(filename,"r") > while 1 do > in = gets(fn) if in=-1 then exit end if > append_text(M,in) > end while > end procedure</eucode> {{{ > (M is my TextCtrl) > > The code i've got will open the file and put all of the text into the > TextCtrl, including the markups (the /t and /par stuff but that just needs > a filter). However, there is another problem that arises. > > I don't know how to stop append_text from getting the text in the file so, it > eventually tries to go past what is in the file, generating a new error... > > type_check failure, val is -1 > > I don't know how to stop the code from hitting the bottom or to check for -1. > I've tried to set val as something and then an if statement to make it stop > when it hits -1 but it passes it up. Don Cole
10. Re: Open command in wxEuphoria
- Posted by don cole <doncole at pacbell.net> Jun 29, 2006
- 641 views
- Last edited Jun 30, 2006
Jesse Adkins wrote: > > I actually did a little modification of my own just now. > }}} <eucode> > procedure load_project(sequence filename) > integer fn > object in > > -- start with a quick sanity check > if match(".rtf",filename)!=length(filename)-3 then > puts(1,"not a project!\n") > end if > fn= open(filename,"r") > while 1 do > in = gets(fn) if atom(in) then --better yet exit end if > append_text(M,in) > end while > end procedure</eucode> {{{ > (M is my TextCtrl) > > The code i've got will open the file and put all of the text into the > TextCtrl, including the markups (the /t and /par stuff but that just needs > a filter). However, there is another problem that arises. > > I don't know how to stop append_text from getting the text in the file so, it > eventually tries to go past what is in the file, generating a new error... > > type_check failure, val is -1 > > I don't know how to stop the code from hitting the bottom or to check for -1. > I've tried to set val as something and then an if statement to make it stop > when it hits -1 but it passes it up. Don Cole
11. Re: Open command in wxEuphoria
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Jun 30, 2006
- 659 views
Jesse Adkins wrote: > > I don't know how to stop append_text from getting the text in the file so, it > eventually tries to go past what is in the file, generating a new error... > > type_check failure, val is -1 > > I don't know how to stop the code from hitting the bottom or to check for -1. > I've tried to set val as something and then an if statement to make it stop > when it hits -1 but it passes it up. When gets reaches the end of the file, it returns -1. You need to change your read loop to:
in = gets(fn) while sequence(in) do append_text(M,in) in = gets(fn) end while
Matt Lewis