Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Database is using table ?
Message
From
08/08/2009 15:05:06
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01416848
Message ID:
01416888
Views:
67
This message has been marked as the solution to the initial question of the thread.
>I used "select 0" for many years in code below with free tables
>
>Now I added my tables to a database and get error "table in use" if I run the code
>
>if I remove "select 0" problem does not happen
>
>What code can I write instead of select 0 ?
>(this is a program, not a forma method)

The Select 0 needs to be inside the loop. For each new table you need to go to a new workarea.

A simpler way to make sure the table isn't opened twice is to extract an alias...
* USE (lcAppendIntoPath+aTables[i,1]) 
lcTable=lcAppendIntoPath+aTables[i,1]
lcAlias=juststem(lcTable)
use (lcTable) again alias (lcAlias) in select(lcAlias)
If the table was already used under a different alias, we're using it AGAIN, so no problem there. If the alias is not in use, select(lcAlias) is same as select(0), i.e. the next available workarea. If it is, well, we're just reopening it in the same workarea where it was open already, so no problem there either.

Note that juststem(lcTable) as an alias will not work if it returns a bad name - i.e. if it contains spaces or punctuation marks, or if it begins with a number. Not all filenames are good as alias (or variable, for that matter) names.


>***********************************************
>
>
>conta_erro = 0
>N_ERRO = 0
>
>
>* set excl on
>
>STORE SYS(5) + curdir() + "dados" TO MyIntoPath && diretorio atual
>
>lcAppendIntoPath = ADDBS(myIntoPath)
>lnNumTables = ADIR(aTables,lcAppendIntoPath+"*.dbf")
>
>*CLOSE DATA
>
>SELECT 0 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Here is the problem
>
>FOR I = 1 TO lnNumTables
>
>*= MESSAGEBOX (lcAppendIntoPath+aTables[i,1])
>
> TRY
>
>*SELECT * FROM (lcAppendIntoPath+aTables[i,1]) INTO CURSOR TMP1
>*use
>
>
>USE (lcAppendIntoPath+aTables[i,1])
>
>
> CATCH TO oErr
> n_erro = oErr.ErrorNo
>
>= MESSAGEBOX (lcAppendIntoPath+aTables[i,1] + " " + STR( N_ERRO))
>
>IF N_ERRO # 0
>conta_erro = conta_erro + 1 && se tiver erro vai acumulando pois passa aqui várias vezes
>
>
>ENDIF
>
>
>DO CASE
>
>
> CASE n_erro = 15
>
> = MESSAGEBOX ("TABELA CORROMPIDA ERR0 15: " )
>
>
> CASE n_erro = 41
>
> = MESSAGEBOX ("TABELA SEM FTP: ")
>
>
> CASE n_erro = 1707 && corrompida, fpt, sem CDX
>
> = MESSAGEBOX ("TABELA SEM CDX: ")
>
>
> CASE n_erro = 114 && corrompida, fpt, sem CDX
>
> = MESSAGEBOX ("TABELA NÃO CONFERE COM O CDX: " )
>
>
> CASE n_erro = 2091 && corrompida, fpt, sem CDX
>
> = MESSAGEBOX ("TABELA CORROMPIDA ERRO 2091 :" )
>
>
> THISFORM.Refresh
>
> OTHERWISE
>
>
>ENDCASE
>
>
>
>ENDTRY
> ENDFOR
>
> CLOSE DATABASES
>
>
> if conta_erro # 0 && SE TIVER ERROS
>
> DO case
>
>
> CASE n_erro = 15 OR n_erro = 41 OR n_erro = 1707 OR n_erro = 114 OR n_erro = 2091
>
> = MESSAGEBOX("Os dados estao corrompidos. Recomendamos enviar a pasta dados para ser analisada. Ou restaure do backup")
>
> other
>
> = MESSAGEBOX ("Erro: " + STR (N_ERRO)+ " Se houver outra instância do software aberta na mesma máquina ou em rede, vá até o menu principal do outro programa que está aberto e clique em opçoes e depois em fechar arquivos.Se o problema persistir informe o erro ao nosso suporte ")
>
> SET EXCLUSIVE OFF
>
>
>
> other
>
>
>
> ENDCASE
>
> ELSE
>
>
> ENDIF
>
>
>SET EXCLUSIVE OFF

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform