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

sys(2015) question 4

Status
Not open for further replies.

fredgmain

IS-IT--Management
Oct 30, 2009
22
MY
Hi all,

Is SYS(2015) is the only VFP fuction that returns unique number?

I try use it as a "login session id" for the app. This "id" will be used to track/link all the activities withn the system access, like runnung reprots, add/edit/dele information and etc. Is this a good way?

Thanks in advance.
Fred
 
Nope.
If you have more than one computer working with your application you may have the same values generated with SYS(2015).

If you want something unique, just generate a GUID.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Fred,

As Borislav points out, SYS(2015) is only unique for a given computer. Althought it's unlikely, it's possible that two different computers could generate the same value.

An easy way to guard against that is to concatenate SYS(2015) with the user name, machine name, or both. For example:

SYS(0) + SYS(2015)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike, Borislav,

I agree that GUID is the better option. You can even generate the same SYS(2015) on the same computer, if it's done in two seperate processes.

For the purpose of having a "session key", you could use getenv('computername')+transform(_vfp.processid)+' '+transform(_vfp.threadid).

Bye, Olaf.
 
sys(2015) depends on datetime to generate the value and is only unique if called from the same session on the same computer. Instead use GUID as Boris said:

Code:
Procedure UniqueID
Local pGUID,rGUID
Declare Integer UuidCreate In 'RPCRT4.dll' String @pguid
Declare Integer StringFromGUID2 In 'Ole32.dll' ;
	string rguid, String @lpsz, Integer cchMax

pGUID=Replicate(Chr(0),16)
rGUID=Replicate(Chr(0),80)

UuidCreate(@m.pGUID)
StringFromGUID2(m.pGUID,@m.rGUID,40)
RETURN CHRTRAN(Strconv(Left(m.rGUID,76),6),'{}','')
endproc

Cetin Basoz
MS Foxpro MVP, MCP
 
Dear all,

Many thanks for all the inputs. I have tried the GIUD and it works for my application.

Have a good day!

Regards,
Fred
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top