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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening multiple dbf files neatly

Status
Not open for further replies.

coldan

Programmer
Oct 19, 2008
98
AU
I write utilities for another application which has over 20 tables of which I need some 15 or so open.

In the past my prg has individual openings for each table like
<code>
If !Used(cMyTableName14)
Use (cMyTableName14)Alias TEMP_NPV In 0 Excl

If lTableError = .T.
Do ermsg With 'TEMP_NPV'
Endif
Endif
</code>

where cMyTableName14 is the full file path

However if one of the required tables is absent I get an 'open' error.

So I decided to test for that - function file(cTable) let me down so I used ADIR()

INSTALLS is already open

My calling command is

Do tbl_opening With cMyTableName14,'TEMP_NPV'

my opening routine is

<code>
Procedure tbl_opening

Parameters myfile,tempter

Local gnPos,gcname

**** was using if file(myfile)

Adir(gadatabase, '*.dbf')

gcname=Justfname(myfile)

gnPos = Ascan(gadatabase, gcname) && Search for company

If gnPos = 0

Do ermsg With gcname

Else

lTableError = .F.
If !Used(myfile)
Use (myfile)Alias (tempter) IN 0
Select (tempter)
logging('Opening '+gcname+' as '+tempter + ' alias ' +Alias())
Endif
If lTableError = .T.
Do ermsg With myfile
Endif
Endif
</code>

my log shows

6:09:36 PM go_openfiles.prg - opening TMG tables
6:09:36 PM Opening MY NEW PROJECT_NPV as TEMP_NPV alias INSTALLS
6:09:37 PM File Open Error!

It must be a simple change to allow each table to be opened.

Can anyone point me in the right direction please?

Thanks in advance.

Colin
 
You can't use the USED() function with a full path, USED() is there to check, if an ALIAS is used, not if a file is already open. That's your first problem.

As you input the alias name a table should get, you should check USED(tempter), as that is the alias you will set when opening the table.

You can only use each alias once. While using IN 0 makes sure you don't use a workarea number twice, you also must ensure you use an ALIAS only once.

Your logging shows, there already was something wrong in openeing the first table, it didn't get the alias "TEMP_NPV" and Select (tempter) didn't selected it, because ALIAS() otherwise would have been "TEMP_NPV" and not "INSTALLS".

All in all this should improve it a bit:
Code:
Procedure tbl_opening
Parameters myfile,tempter

IF Adir(gatable, myfile)=0
   Do ermsg With myfile
Else    
   lTableError = .F.    
   If !Used(tempter)      
      Select 0
      Use (myfile) Alias (tempter) IN 0        
      logging('Opening '+Justfname(myfile)+' as '+tempter + ' alias ' +Alias()) 
   Else
      lTableError = .T.   
   Endif    
   If lTableError = .T.        
      Do ermsg With myfile
   Endif
Endif

If you use a database (DBC), then you can simply check without FILE() or ADIR(), if a table does belong to the currently active database by INDBC().

Bye, Olaf.
 
Code:
[b][COLOR=red]Select 0[/color][/b]
Use (myfile) Alias (tempter) [b][COLOR=red]IN 0[/color][/b]

One of these is one more :)

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Well, then only delete the IN 0, not the SELECT 0, as it is neededto have the work area active, in which the table is opened. Or leave it as it was:

USE ... ALIAS (tempter) ... IN 0
SELECT (tempter)

Which also selects the workarea by the alias given.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top