Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Duplicate numbers
Message
 
To
16/03/2010 22:24:23
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01454921
Message ID:
01455067
Views:
36
>Hi Greg, thank you for your reply. I can not lock the whole table because it is used for other things. But I tried to lock the record and pass the next barcode number but on occasions, the number was duplicated if two operators where working on the system. When I closed and open the table, plus the rlock(), it seems to behave and I haven't seen any duplicates yet. Here is my modified code :
>
>
>IF USED("barcno")
>	USE IN barcno
>ENDIF
>IF NOT USED("barcno")
>	SELECT 0
>	USE barcno
>endif		
>select barcno 
>
>nBarc=barcno.barcno  
>IF nBarc <= 0
>	MESSAGEBOX("This computer is not setup with barcode numbers","")
>	RETURN
>ENDIF 
>IF RLOCK('barcno')	
>	replace barcno with nBarc+1
>	UNLOCK
>else 
>       MESSAGEBOX("The barcodes numbering file is in use, plese try again","")
>	RETURN
>ENDIF 	
>FLUSH in barcno force
>IF USED("barcno")
>	USE IN barcno
>ENDIF
>
The only thing I would change at this point would be to elimate saving the barcno field to the memory variable. It is possible that two users could almost simultaneously enter into this code and cause it to fail....
1st person enter code and saves barcno to nBarc.
2nd person enters right behind and also saves the same value from barcno to nBarc.
1st person hits the lock first, and updates barcno to nBarc + 1. 2nd person is held up by lock.
1st person unlocks record and departs.
2nd person now locks the record and locks it... but to no avail... saves the old nBarc + 1 to barcno again... instead of nBarc + 2.

This is how I would try it...
IF USED("barcno")
	USE IN barcno
ENDIF
IF NOT USED("barcno")
	SELECT 0
	USE barcno
endif		
select barcno 

*nBarc=barcno.barcno  
*IF nBarc <= 0
IF barcno.barcno < = 0
	MESSAGEBOX("This computer is not setup with barcode numbers","")
	RETURN
ENDIF 
IF RLOCK('barcno')	
*	replace barcno with nBarc+1
                replace barcno with barcno + 1
	UNLOCK
else 
       MESSAGEBOX("The barcodes numbering file is in use, plese try again","")
	RETURN
ENDIF 	
FLUSH in barcno force
IF USED("barcno")
	USE IN barcno
ENDIF
Tommy Tillman A+ NetWork+ MCP
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform