Page Index Toggle Pages: 1 [2]  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) File Open is not working anymore. (Read 3369 times)
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
 
Page Index Toggle Pages: 1 [2] 
Send Topic Send Topic Print Print