Hot Topic (More than 10 Replies) File Open is not working anymore. (Read 3498 times)
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
File Open is not working anymore.
Aug 17th, 2004 at 7:31pm
Print Post Print Post  
For some reason, I cant get Sesame to open a .txt file. I've tried several different programs, and none of them will read the contents of the file. The file is a plain text file (copied from website and pasted into excel, then saved as .TXT). It opens fine in notepad:

var vall as string = ""
vall = @insert("c:\temp\colors5.txt")
writeln("vall = " + vall)

The writeln window is blank. also:

var vfilehandle as int
var vfilesize as int
var vfile as string
var vline as string = ""

if fileExists("C:\temp\colors5.txt") then writeln("Found it") else writeln("Cant find it!")

vfilehandle = fileopen("c:\temp\colors5.txt")
vfilesize= filesize(vfilehandle)
filereadln(vfilehandle, vline)
writeln(vline)

Here the writeln window shows "Found it"  and nothing else.

I restarted client, and put the text file in the c:\temp folder on BOTH client and server, but still no luck.

Any ideas? I've never had this problem before.

Steve
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: File Open is not working anymore.
Reply #1 - Aug 17th, 2004 at 7:39pm
Print Post Print Post  
Excel has a bunch of different formats it calls TXT. They do not all result in the format of text file you might expect. Can you open other text files that have not been processed in this way by Excel?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #2 - Aug 17th, 2004 at 7:47pm
Print Post Print Post  
Yes, other text files are being opened just fine. Also, I've used this routine before and occasionally run into a problem where sesame doesnt find certain character such as @newline().

But it seems this time, sesame cant read any of it at all. Using @Asc(vline) just returns 0.

Can you think of a way to get the data in excel into a more Sesame friendly format? Pasting from Excel into notepad doesn't help and I dont see an 'export' tool in excel.

Thanks,
Steve


  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: File Open is not working anymore.
Reply #3 - Aug 17th, 2004 at 8:06pm
Print Post Print Post  
Which of the txt options are you using from Excel? You might try tab delimited or csv and see if that helps. 

In Excel, Save As is how you "export". I've found Excel to be a bit flaky about doing this, especially in situations where, for example, the last cell is blank. Stuff like that.

Send us the text file. We'll look at in something that doesn't hide anything and let you know what we see.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #4 - Aug 17th, 2004 at 8:12pm
Print Post Print Post  
I always save as .csv from excel which usually works fine.

I'll send you the text file. Thanks for the help.

Steve
  
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: File Open is not working anymore.
Reply #5 - Aug 17th, 2004 at 11:00pm
Print Post Print Post  
As noted earlier, not all TXT files are the same.  And NotePad does use a format that is not common to many other editors.  Unicode sometimes may also be a factor.

But let me question the use of Excel.  Is it really necessary?  You may be able to copy from the Web directly into a text editor of choice.

If you have copied a table, then you can do a Search/Replace in the editor replacing Tab chars with your comma, and save as text.

Can you provide the web link and describe what you are copying into the text file?


  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #6 - Aug 17th, 2004 at 11:14pm
Print Post Print Post  
Bob,

I copied a table (chart?) and which pasted nicely into excel. Then I used Excels features and speed to do a lot of search/replacing. Keeping things in neat rows and columns is essential.

Then I saved to a .csv and usually import it right into sesame using Sbasic programming.

Maybe I should look at search/replace program other than excel. (Notepad is SOO SLOOOWW, but necessary to 'clean up' the .csv before importing into Sesame)

Thanks,
Steve
  
Back to top
IP Logged
 
jondolar
Junior Member
**
Offline


Keep Trying

Posts: 57
Location: Montreal Canada
Joined: Dec 25th, 2003
Re: File Open is not working anymore.
Reply #7 - Aug 17th, 2004 at 11:28pm
Print Post Print Post  
Hi Steve

Use WordPad. It has a find and replace feature and comes standard with every version of Windows. Your "Cleaning job" will be much easier. Wink

Take care

Serge



  

When all you have is a hammer, everything starts to look like nail!
Back to top
 
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #8 - Aug 18th, 2004 at 12:16am
Print Post Print Post  
Thanks Serge. I have found Word pad to be much faster, but I was worred that wordpad my add change my "generic text" to "Rich Text" and further complicate things during my import into sesame. Also, the 'wordwrap' throws my lines out of whack. I like to see the data as 'raw' as possible.

Thanks for all the suggestions. Keep em coming.

Steve
  
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #9 - Aug 18th, 2004 at 1:01am
Print Post Print Post  
Bob,

I tried another d/l of the text from the website. I saved it as a csv and opened it into notepad. All went well, I then saved it and tried to import it into sesame.....nothing. Sesame sees it as a blank file. It wont even writeln the to the screen. (same as before).

So this issue has nothing to do with Excel. The website that I'm getting the data from is not giving me plain text.

I'll need to wait to see what the Lanticans come up with.

Thanks for everyones help. Hopefully I'll hear from Erika tomorrow.

Steve


ps. I'd give you the link to the site, but its password protected info.

  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: File Open is not working anymore.
Reply #10 - Aug 18th, 2004 at 3:07pm
Print Post Print Post  
Steve,

I now have your file, and I am seeing a few problems, some with the SBasic (as posted) and a minor problem with the file.

The following SBasic will not work because of the length of the file: 
Code
Select All
var vall as string = ""
vall = @insert("c:\temp\colors5.txt")
writeln("vall = " + vall)
 


The file is 382K as received. The writeln window will vertically wrap every 32K (clear, and start at the top again) and dumping 382K on a single line is just too much for it to manage. You will need to break your string into smaller pieces if you need to send them to the writeln window, so each line of text is smaller.

The good news is that the variable "vall" is getting set to the entire string - even if that cannot be shown using a single writeln call.

The other attempt to read the file is suffering because, FileOpen expects to be used read/write - so if the file already exists it positions the "file pointer" (the position where the next operation will occur in the file) to the end of the file - to make appending to an existing file very easy. Before reading from an existing file, you should always do a "FileSeek" operation. The following will read the first line in your file:
Code
Select All
vfilehandle = fileopen("c:\temp\colors5.txt")
fileseek(vfilehandle, 0)
filereadln(vfilehandle, vline)
writeln(vline)
fileclose(vfilehandle)
 


The last problem I am seeing, is that the file is not "DOS" formatted. All operating systems other than those from Microsoft (Unixes, VMS, Mac, etc..) end each line with a single line feed. Microsoft OSs (on the other hand) end each line with a linefeed / carriage return pair. The file you sent only has the single linefeed. So, it appears that it originated on an operating system other than a Microsoft OS. This is not a bad problem because Sesame and most other programs are built to accomodate either line ending.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #11 - Aug 18th, 2004 at 3:24pm
Print Post Print Post  
Thanks Mark, I assumed the fileseek was not needed. I'll add it to my routine.

Also, as I import this file into sesame, can I continue to use the 'split(vline, @newline())' command or are you saying there are no linefeeds in that file?

If not, what do I need to do to have sesame parse that file line by line? SHould I just go in and press enter at the end of each line in notepad (hopefully not).

Thanks again for your help,

Steve
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: File Open is not working anymore.
Reply #12 - Aug 18th, 2004 at 4:54pm
Print Post Print Post  
Quote:
Thanks Mark, I assumed the fileseek was not needed. I'll add it to my routine.

Also, as I import this file into sesame, can I continue to use the 'split(vline, @newline())' command or are you saying there are no linefeeds in that file?

If not, what do I need to do to have sesame parse that file line by line? SHould I just go in and press enter at the end of each line in notepad (hopefully not).

Thanks again for your help,

Steve


The file does have linefeeds. It seems to missing carriage returns. That should be okay and you probably won't need to do anything about that.

I would recommend that you get rid of the @Insert and its accompanying WriteLn, and use the file I/O to read the file in one line at a time. That way, you do not have to parse it into separate lines at all. Once you have read a line you can parse it, or concatenate it, or merely send it to the "slate" with WriteLn - as is needed.

Anything you pass to WriteLn, WriteLn will treat as one big "chunk" even if it has linefeed embedded in it. It measures the string length - not the line length. A string can have many lines in it, each demarcated with either a single linefeed or a lf/cr pair.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #13 - Aug 18th, 2004 at 5:54pm
Print Post Print Post  
Thanks again. I added the writeln just for the sake of this example and to see if it was working.

My problem lies in the fact that i didnt use FileSeek.

I'll give it a try.

Thanks for all your help.

Steve
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: File Open is not working anymore.
Reply #14 - Aug 18th, 2004 at 5:57pm
Print Post Print Post  
You're welcome.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #15 - Aug 18th, 2004 at 8:59pm
Print Post Print Post  
I'm getting a message I was getting earlier:

Internal Error: Runtime Stack Underflow.

Does this mean that my .txt file is too large for sesame to handle? Excel shows the file has 4500 lines approx. The client machine has 256 MB of Ram.

The program is pasted below.

Steve
var vfilehandle as int
var vfilesize as int
var vline as string = ""
var x as int = 1
var vrecord as string = ""
VAR t as array [5000,4] of string
var z as int
var nn as int
var vall as string
var vresults as int
var vfile as string

if fileExists("C:\temp\color7.txt") then writeln("Found it") else writeln("Cant find it!")


vfilehandle = fileopen("c:\temp\color7.txt")
vfilesize= filesize(vfilehandle)
fileseek(vfilehandle, 0)

while (filepos(vfilehandle)) < (vfilesize)
{
filereadln(Vfilehandle, vline)
t[x,1] = split(vline, ",") + ","
t[x,1] += split(vline, ",") + ","
t[x,1] += split(vline, ",") + ","
t[x,2] = split(vline, ",") //all with no spaces
t[x,3] = split(vline, ",") //size
t[x,4] = split(vline, @newline())   //stock number
x=x+1
}

fileclose(vfilehandle)

  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: File Open is not working anymore.
Reply #16 - Aug 19th, 2004 at 12:03pm
Print Post Print Post  
Steve,

Some preliminary results from testing your code:
Quote:
Internal Error: Runtime Stack Underflow.

Does this mean that my .txt file is too large for sesame to handle? Excel shows the file has 4500 lines approx. The client machine has 256 MB of Ram.

No, 4500 lines is easily handled. That error (in this case) is coming from the "+=" operator. When I replaced:
Code
Select All
t[x,1] = split(vline, ",") + ","
t[x,1] += split(vline, ",") + ","
t[x,1] += split(vline, ",") + ","
 


With:
Code
Select All
t[x,1] = split(vline, ",") + ","
t[x,1] = t[x,1] + split(vline, ",") + ","
t[x,1] = t[x,1] + split(vline, ",") + ","
 


The error goes away. The two constructs are supposed to be identical. The "+=" operator is borrowed from a different language (the computer language called "C") the second construct is the typical way to concatenate in BASIC. I am now looking into the "+=" operator to see why it is acting differently. It is either having a problem with strings, or with arrays - you have both, so I am not sure which is giving it grief.

In the category of good advice, before you deploy this code, please make sure that you are checking if the file exists before you attempt to open it and that you have successfully opened it before you attempt to check file size or read. The check you do have, informs the user, but provides no means to prevent the subsequent operations.
Code
Select All
var vfilehandle as int
var vfilesize as int
var vline as string = ""
var x as int = 1
var vrecord as string = ""
VAR t as array [5000,4] of string
var z as int
var nn as int
var vall as string
var vresults as int
var vfile as string

if fileExists("C:\temp\color7.txt")
{
 writeln("Found it")

 vfilehandle = fileopen("c:\temp\color7.txt")
 if(vfilehandle > 0)
 {
  vfilesize = filesize(vfilehandle)
  fileseek(vfilehandle, 0)

  while(filepos(vfilehandle) < vfilesize)
  {
   filereadln(Vfilehandle, vline)
   t[x,1] = split(vline, ",") + ","
   t[x,1] = t[x,1] + split(vline, ",") + ","
   t[x,1] = t[x,1] + split(vline, ",") + ","
   t[x,2] = split(vline, ",") //all with no spaces
   t[x,3] = split(vline, ",") //size
   t[x,4] = split(vline, @newline())   //stock number
   x = x + 1
  }
  fileclose(vfilehandle)
 }
}
else
{
 writeln("Cant find it!")
}

 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: File Open is not working anymore.
Reply #17 - Aug 19th, 2004 at 12:45pm
Print Post Print Post  
Just as a note: it appears that the "+=" is having problems with strings arrays. It seems to work correctly on ordinary strings.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #18 - Aug 19th, 2004 at 1:17pm
Print Post Print Post  
Thanks for the info.

I'll give it a try.

Steve
  
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #19 - Aug 19th, 2004 at 1:45pm
Print Post Print Post  
Yeah Mark! You fixed it.

Thank you!

Steve
  
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #20 - Aug 19th, 2004 at 4:48pm
Print Post Print Post  
Mark,

I want to put this program into a mass update but the T array needs to be available to every record in the mass update.

The program works with the first record, but then the array is killed when the record changes to the next one.

I put ' Var T as array(5000, 5) as string' in the Global Code section so it would not be killed between records, but now I'm freezing up.

Here's the program that is in a 'general area' of Mass Update:

var vfilehandle as int
var vfilesize as int
var vline as string = ""
var x as int =1
var vrecord as string = ""
var nn as int
var vall as string
var vresults as int
var vfile as string

if @formresultsetcurrentposition("admin") = 1 then
{
if fileExists("C:\temp\shawimport.txt") then writeln("Found it")

vfilehandle = fileopen("c:\temp\shawimport.txt")
vfilesize= filesize(vfilehandle)
fileseek(vfilehandle, 0)

while (filepos(vfilehandle)) < (vfilesize)
{
filereadln(Vfilehandle, vline)
t[x,1] = split(vline, ",") + ","
t[x,1] = t[x,1] + split(vline, ",") + ","
t[x,1] = t[x,1] + split(vline, ",") + ","
t[x,2] = split(vline, ",") //all with no spaces
t[x,3] = split(vline, ",") //size
t[x,4] = vline   //stock number
x=x+1
}
z=x-1
fileclose(vfilehandle)
}//end of file open

vrecord = COLLECTION + pattern + color
vrecord = @replace(vrecord, " ", "")
vrecord = @replace(vrecord, "-", "")
vrecord = @replace(vrecord, "'", "")
writeln("Vrecord = " + vrecord)

x=1
writeln("about to scroll through lines since x = " + x + " and z = "+z)

while x <= z
{
//writeln("Comparing :" + t[x,1] + " against " + vrecord)

if t[x,2] = vrecord then
{
nn=@formnewrecord("Variants")
formfieldvalue("Variants", "mfgr", nn, "Shaw2")
formfieldvalue("variants", "variant Name", nn, t[x,3])
formfieldvalue("Variants", "part number", nn, t[x,4])
writeln("Found "+ collection + " " + pattern + " " + color + " on line "+x)
t[x,1] = ""
t[x,2] = ""
t[x,3] = ""
t[x,4] = ""
}
x=x+1
} //keep looping till end

writeln("processing record " + @formresultsetcurrentposition("admin") )

vrecord = ""


if @formresultsetcurrentposition("admin") = @formresultsettotal("Admin")
{
writeln("NOW writing results")
vresults = fileopen("C:\temp\results.txt")

x=1

while x <= z
{
if t[x,1] <> "" then
{
filewrite(vresults, t[x,1])
filewrite(vresults, t[x,3])
filewrite(vresults, ",")
filewriteln(vresults, t[x,4])
}
x=x+1
}// loop to write file

fileclose(vresults)
}//end of last record.




Edit: The globalCode section contains:
var z as int
VAR t as array [5000,4] of string


  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: File Open is not working anymore.
Reply #21 - Aug 19th, 2004 at 4:59pm
Print Post Print Post  
Steve,

Try
stat T as array(5000, 5) as string

Otherwise, your array goes out of scope as soon as Global Code finishes running.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: File Open is not working anymore.
Reply #22 - Aug 19th, 2004 at 5:02pm
Print Post Print Post  
Thanks Erika. Looks like that did it! Still a bug somewhere, but I think I can find it.

I appreciate everyones help and your suggestion of using Mass update rather than manually advancing records using sbasic during an export. Great idea!

Steve
  
Back to top
IP Logged