Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load DB and export Query

Status
Not open for further replies.

GermanB

Programmer
Nov 22, 2001
5
AR
Hi. I have years of programming but I'm not too familiar with VFP, and I'm looking for hints on something I have to do. I want to open a DBF file whose name is not fixed, I could either get it as a parameter from another program or let the user select the file while in the VFP application. The database will have a structure that I already know, I would execute a query on it (the query could be hardcoded, it's always the same), then I want to export the results to a file with "type sdf". The output file should have the name of the original DBF but with extension TXT.
I always make these steps interactively but I want a program to make it more automatic. Actually I haven't written any programs at all with VFP, so any help is appreciated!!
Thanks
G
 
I use the ADIR() function to store the names of the dbf's to an array. You can then create a form and use the ADDITEM property of a COMBOBOX to populate it with the dbf names.

Below is the code I put in the init of the form:

PUBLIC gcDate, gaFilesFnd

gcDate = ""

DIMENSION gaFilesFnd(1,1)

ADIR(gaFilesFnd,"x:\ptfs30\databs\test~~~~\PT*.DBF")
ASORT(gaFilesFnd,1,10000) ** This is optional
FOR y = 1 TO ALEN(gaFilesFnd,1)
THISFORM.combo1.AddItem(LEFT(RIGHT(LEFT(gaFilesFnd(y,1),8),6),2)+'/'+RIGHT(LEFT(RIGHT(LEFT(gaFilesFnd(y,1),8),6),4),2)+'/'+RIGHT(RIGHT(LEFT(gaFilesFnd(y,1),8),6),2))
ENDFOR
 
PS. Once you have the data in a cursor you can use the 'COPY TO' command to export the file.

EXAMPLE:

SELECT MyTable
COPY TO mytable.txt SDF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top