Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Andy Kramek
  Where is Andy Kramek?
 Westminster Circle, Akron
 Ohio - United States
 Andy Kramek
 To: bryan wetton
  Where is bryan wetton?
 Morphett Vale
 Australia
 bryan wetton
 Tags
Subject: RE: opening multiple tables in one routine
Thread ID: 209088 Message ID: 209123 # Views: 48 # Ratings: 1
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Wednesday, December 24, 2008 12:20:17 PM         
   


> I have developed an application which uses over 17 tables from another application.
>
> I want to make a copy of each table with a new name in a folder and open each one.
>
> At present I am using the following code each time
>
> eg for TEMP_C
>
>
> 
> SELECT TEMP_C
> 
> myorigfilename ="TEMP_C"+'.dbf'
> 
> mycopyfilename = "TEMP_CC"+'.dbf'
> 
> CopyFile (myorigfilename , mycopyfilename, 0)
> 
> myorigfilename ="TEMP_C"+'.fpt'
> 
> mycopyfilename = "TEMP_CC"+'.fpt'
> 
> CopyFile (myorigfilename , mycopyfilename, 0)
> 
> *!*	COPY to TEMP_CC - replaced by API call
> 
> USE
> 
> IF !used('TEMP_CC')
> 	USE TEMP_CC in 0
> ENDIF
> 
> 

>
> Can a clever more experienced coder than me put all this in a FOR NEXT form that I can use instead?
>
> I will manually create an array of the old TEMP filenames and corresponding new TEMP filenames as they will never change.
>
> I already have many prgs using the new filenames.
>
> I am doing this so that the tables form the original application are not changed by my app.

You don't need to copy the files explicitly like that at all. You could simply use code like this (not tested - assumes that you are either in the correct location for all files and that you have paths set to those needed if not!):

BEGIN TRY
  *** Delete any existing files
  IF FILE( 'temp_cc.dbf' )
    USE IN SELECT( 'temp_cc' ) && Ensure it is not in use
    DELETE FILE temp_cc.*      && Delete all files named temp_cc (i.e. dbf, fpt, cdx)
  ENDIF

  *** Now Open the source file  for copying
  IF NOT USED( 'temp_c' )     && USED() requires an ALIAS not a file name!
    USE temp_c IN 0 SHARED NOUPDATE
  ENDIF
  SELECT temp_c
  *** Use the copy command to copy all files:
  COPY TO temp_cc PRODUCTION   && Copies DBF, FPT and CDX file

  *** Alternatively you simply use a SQL query that doesn't 
  *** need you to explicitly open the source file first but 
  *** that won't get any associated index file
  *** SELECT * FROM temp_c INTO TABLE temp_cc

  *** Open the new copy for use
  USE temp_cc IN 0

CATCH TO loErr
   MESSAGEBOX( loErr.Message, 16, 'Error' )

FINALLY
  *** Always close the original file no matter what!
  USE IN SELECT( 'temp_c' )
END TRY



Regards
Andy Kramek
Microsoft MVP (Visual FoxPro)
Tightline Computers Inc, Akron Ohio, USA



COMPLETE THREAD
opening multiple tables in one routine Posted by bryan wetton @ 12/24/2008 6:58:11 AM
RE: opening multiple tables in one routine Posted by Brad Schulz @ 12/24/2008 8:09:38 AM
RE: opening multiple tables in one routine Posted by bryan wetton @ 12/25/2008 8:29:48 AM
RE: opening multiple tables in one routine Posted by Brad Schulz @ 12/27/2008 6:59:58 PM
RE: opening multiple tables in one routine Posted by bryan wetton @ 12/28/2008 2:48:51 AM
RE: opening multiple tables in one routine Posted by Stefan Wuebbe @ 12/28/2008 10:26:40 AM
RE: opening multiple tables in one routine Posted by bryan wetton @ 12/29/2008 12:37:26 PM
RE: opening multiple tables in one routine Posted by Brad Schulz @ 12/29/2008 7:26:41 PM
RE: opening multiple tables in one routine Posted by Stefan Wuebbe @ 12/29/2008 7:40:52 PM
RE: opening multiple tables in one routine Posted by bryan wetton @ 12/30/2008 7:59:40 AM
RE: opening multiple tables in one routine Posted by bryan wetton @ 12/30/2008 7:53:24 AM
RE: opening multiple tables in one routine Posted by Stefan Wuebbe @ 12/29/2008 7:38:40 PM
RE: opening multiple tables in one routine Posted by Jyothish KV @ 12/24/2008 8:49:56 AM
RE: opening multiple tables in one routine Posted by Andy Kramek @ 12/24/2008 12:20:17 PM