Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
USE command- I think I've gone crazy.
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00473226
Message ID:
00473289
Views:
21
Hi Troy,

What does ? on('error') return? You may have your own Error Handler, which doesn't show the errors on these commands. I also think, that instead of plain use better use wrapper function. This is my wrapper function for the use command:
********************************************************************
*  Description.......: OpenTable && Opens the passed table
*  Calling Samples...: OpenTable('TranMstr','WorkFile')
*  Parameter List....: tcTable, tcAlias, tcMode, tcTagOrder, tnBufferMode
*  Created by........:
*  Modified by.......: Nadya Nosonovsky 01/10/2001 11:46:19 AM
********************************************************************
function OpenTable
lparameters tcTable, tcAlias, tcMode, tcTagOrder, tnBufferMode
*=messagebox( "tcTable "+tcTable+ chr(13)+"tcTagOrder "+iif(!empty(tcTagOrder),tcTagOrder,""))
* tcTable - required: name of table to open (with or without full path)
* tcAlias - optional: alias name, if different from tcTable
* tcMode - optional:  mode in which table should be opened, like Shared noupdate
* tcTagOrder - optional: Tag name
* tnBufferMode - optional: Set buffer mode
local lcTableName, lnPos, llDBCPrefix, lcDBCName
* Check parameters first
if empty(tcTable) or vartype(tcTable)<>'C'
* First parameter is required
     return .f.
else
     lnPos=rat('!',tcTable)
     if lnPos>0 && DataBase Name was specified && example: Support!PostOff
          lcTableName=juststem(substr(tcTable,lnPos+1)) && PostOff
          lcDBCName=upper(left(tcTable,lnPos-1)) && DBC Name
          llDBCPrefix=.t.
     else
          lcTableName=tcTable
     endif
endif
if empty(tcAlias) or vartype(tcAlias)<>'C'
     tcAlias=juststem(lcTableName)
endif

if empty(tcMode) or vartype(tcMode)<>'C'
     tcMode='shared'
else
     tcMode=lower(tcMode)
endif
local lcCheckFile
if empty(justext(lcTableName))
   lcCheckFile=forceext(lcTableName,"dbf")
else
   lcCheckFile=lcTableName    
endif  
if !file(lcCheckFile)  && File doesn't exist
     =messagebox(tcTable +' does not exist!. Can not proceed...',48,'Error')
     return .f.
endif
local lnOldSelect
lnOldSelect=select()
if !used(tcAlias) or ; && Alias is not already in use or 
        (llDBCPrefix and not juststem(cursorgetprop("DATABASE",tcAlias))==lcDBCName) && it's not the same database
     local lcOldError, lnErr, lcOldSetExclusive
     use in select(tcAlias) && Close table
     lnErr=0
     lcOldError=on('error') && Save current Error Handler
     lcOldSetExclusive=set('exclusive') && Save current exclusive status
     set exclusive off && This should be always set this way
     on error lnErr=error()
     use (tcTable) again &tcMode in 0 alias (tcAlias)
     on error &lcOldError && Restore previous Error Handler
     if lcOldSetExclusive='ON'
          set exclusive on && Restore it back to original settings
     endif
     if lnErr<>0 && Error occurs
          if lnErr=1705  && File Access is denied
               =messagebox(tcTable +' is opened exclusively by another user. Can not proceed...',48,'Error '+transform(lnErr))
               return .f. && Table could not be opened (already used exclusively)
          else && Another error
               =messagebox(tcTable+' could not be opened!',48,'Error '+transform(lnErr))
               return .f.
          endif
     endif
endif

select (tcAlias) && If it's here, everything is all right
if not empty(tcTagOrder) and vartype(tcTagOrder)='C' and tagno(tcTagOrder)>0
     set order to tag (tcTagOrder) in (tcAlias)
endif 

if vartype(tnBufferMode)='N' and between(tnBufferMode,1,5)
    local lcOldSetMultilocks
    lcOldSetMultilocks=set('multilocks')
    set multilocks on
     =cursorsetprop('Buffering',tnBufferMode) && Note, we can not set buffering mode less than 3 on a view - no check for this
     if lcOldSetMultilocks="OFF"
          set multilocks off && Restore back
     endif
endif
select (lnOldSelect) && Return back to the original area

return .t.
>Got some old code I just inherited. I'm running it in VFP6. It's in a prg- no database containers, no data buffering and no private data sessions.
>
>It has some USE statements:
>USE DBFS\MIR_99 IN 0
>USE DBFS\FAC_INFO IN 0
>USE DBFS\SIZETYPE IN 0
>
>Now the weird part. If I put a break point or a SUSPEND in before the USE commands, then they work perfectly. On the other hand, if I don't put a break point in or I suspend immediately after the USE statements, then the tables do not get USED which causes an error later.
>
>I've never seen anything like this before.
>
>I sure would appreciate any insight on why VFP would behave this way.
>
>Thanks in advance.
>
>Troy
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform