Normal Topic Please help with loop command or ? (Read 1853 times)
billgordon
Junior Member
**
Offline


No personal text

Posts: 61
Joined: Dec 31st, 2003
Please help with loop command or ?
Mar 22nd, 2005 at 6:14pm
Print Post Print Post  
I am trying to use Sbasic to read a whole bunch of csv files to import data. After trying to use the file commands like fileseek, filereadln etc I realized that if I just append the data from all the files into 1 file I can then easily use sesame built in import feature. My problem is, is there an easy way to use sbasic or something else to loop through all the files with the append command

Type 001.csv >> bigfile
Type 002.csv >> bigfile
Type 003.csv >> bigfile
Type 004.csv >> bigfile

And so on till 999

Something like this but with a loop

Var vfilenumber as int

Vfilenumber = 001

Type vfilenumber.csv >> bigfile

Vfilenumber = (Vfilenumber + 1)

Type vfilenumber.csv >> bigfile


Thanks for any help you can offer.
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Please help with loop command or ?
Reply #1 - Mar 22nd, 2005 at 6:26pm
Print Post Print Post  
Code
Select All
Var vFileNumber as Int
Var vFileName as String

vFileNumber = 1

While vFileNumber < 1000
{
	vFileName = @Right("000" + @Str(vFileNumber), 3) + ".csv"
	//Use vFileName to do what you need to
	vFileNumber = vFileNumber + 1
} 



vFilename will have the name of your csv file. It is padded to three numbers like your example showed.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
billgordon
Junior Member
**
Offline


No personal text

Posts: 61
Joined: Dec 31st, 2003
Re: Please help with loop command or ?
Reply #2 - Mar 22nd, 2005 at 6:56pm
Print Post Print Post  
ray the reaper,

Thank you for the help but I am still a little confused.

Question 1
In-between  this line
vFileName = @Right("000" + @Str(vFileNumber), 3) + ".csv"

and this line
vFileNumber = vFileNumber + 1

Is were my action should be placed correct?


Question2

Should I be shelling out to the operating system and using something like
type vFileName >> bigfile.csv

or should I be using  something like

filereadln(vFileName, bigfile.csv)


Thank you for your help

example

var vFileNumber as Int
Var vFileName as String

vFileNumber = 1

While vFileNumber < 1000  // This is saying do what is in the curly brackets until 1000

{
vFileName = @Right("000" + @Str(vFileNumber), 3) + ".csv"
//Use vFileName to do what you need to

// my action command here

vFileNumber = vFileNumber + 1
}


  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Please help with loop command or ?
Reply #3 - Mar 22nd, 2005 at 7:12pm
Print Post Print Post  
Yes your action would be placed there.

That is up to you. You can append the files by using @Shell or you could use SBasic's File I/O commands. Either one will be able to do what you are wanting to do. @Shell will display the dos box for each file you are appending. SBasic's File I/O commands will be more lines of code for you to write.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
billgordon
Junior Member
**
Offline


No personal text

Posts: 61
Joined: Dec 31st, 2003
Re: Please help with loop command or ?
Reply #4 - Mar 22nd, 2005 at 9:15pm
Print Post Print Post  
Thank you Ray The reaper for the help.

Another forum member helped me with the code below that does the trick. He has however suggested that  I add sbasic that checks to make sure the files are in the directory and also rename them as it goes to eliminate the chance of accidental duplication.
(He also said it would be cooler to do it all in sbasic and I should go to the class in Ohio to learn more)

This is the working file

var vFileNumber as Int
Var vFileName as String
Var vFileNameD as String
var vshellfile as string

vFileNumber = 1

While vFileNumber < 1000  // This is saying do what is in the curly brackets until 1000

{
vFileName = @Right("000" + @Str(vFileNumber), 3) + ".csv"
  //Use vFileName to do what you need to

     vFileNameD = ("type c:\buildfile\" + (vFileName) + " >> c:\ buildfile\ Bigfile.csv")
     //writeln(vfilenamed)      
       vshellfile = @shell(vfilenameD)

vFileNumber = vFileNumber + 1
}
  
Back to top
 
IP Logged