Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multi user unique file names?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00625605
Message ID:
00625968
Views:
11
There's much shorter version in the Message #541174.

>Caroline,
>
>>Thanks for the reply, is it just me or isn't this having to use a sledge hammer to crack a nut surely there must be a quick easy way of doing this?
>
>Well, IMO you won't really run into trouble using SYS(2015) to generate unique filenames. Maybe a duplicate filename occurs once a year, maybe a litte more often, maybe never.
>
>Using a GUID as the filename should never create any duplicates.
>
>IMO it's just a matter how safe you want this to be. Using GUIDs is no problem if you have a function that generates the IDs and it's safe. That's why I would use this approach.
>
>Nevertheless, you're right in saying, that there should be an easy way to create unique filenames. But even VB doesn't have a function for this <g>.
>
>>If not then your function would be greatly appreciated.
>
>Here it is:
>
>FUNCTION GetGUID(tllShort)
>
> *-- tllShort: When selecting a guid-column from SQL-Server in a remote view,
> *-- the guid is displayed and to be entered without leading "{" and trailing "}".
> *-- If tllShort is .T., the generated guid is returned in the format, a remote
> *-- view requires it. For use in ADO recordsets tllShort must be omitted or .F.
>
> LOCAL lcRet, lcGUID, lnGUIDLen, lcData1, lcData2, lcData3, lcData4, lcData5
>
> DECLARE INTEGER CoCreateGuid IN OLE32.DLL STRING @lcGUID
>
> *-- Initialize the buffer that will hold the GUID
> lcGUID = REPLICATE(CHR(0),17)
>
> IF CoCreateGuid(@lcGUID) = 0
> *!* Store the first eight characters of the GUID in data1
> lcData1 = RIGHT(TRANSFORM(strtolong(LEFT(lcGUID,4)),"@0"),8)
> *!* Store the first group of four characters of the GUID in data2
> lcData2=RIGHT(TRANSFORM(strtolong(SUBSTR(lcGUID,5,2)),"@0"),4)
> *!* Store the second group of four characters of the GUID in data3
> lcData3=RIGHT(TRANSFORM(strtolong(SUBSTR(lcGUID,7,2)),"@0"),4)
> *!* Store the third group of four characters of the GUID in data4
> lcData4=RIGHT(TRANSFORM(strtolong(SUBSTR(lcGUID,9,1)),"@0"),2) + ;
> RIGHT(TRANSFORM(strtolong(SUBSTR(lcGUID,10,1)),"@0"),2)
>
> *!* Initialize data5 to a null string
> lcData5 = ""
> *!* Convert the final 12 characters of the GUID and store in data5
> FOR lnGUIDLen = 1 TO 6
> lcData5 = lcData5 + RIGHT(TRANSFORM(strtolong(SUBSTR(lcGUID,10+lnGuidLen,1))),2)
> ENDFOR
>
> *!* Check the length of data5. If less than 12, the final 12-len(data5)
> *!* characters are '0'
> IF LEN(lcData5)<12
> lcData5 = lcData5 + REPLICATE("0",12-LEN(lcData5))
> ENDIF
>
> *!* Assemble the GUID into a string
> lcRet = ""
> IF NOT tllShort
> lcRet = "{"
> ENDIF
> lcRet = lcRet + lcData1 + "-" + lcData2 + "-" + lcData3 + "-" + lcData4 + "-" + lcData5
> IF NOT tllShort
> lcRet = lcRet + "}"
> ENDIF
> ELSE
> lcRet = ""
> ENDIF
>
> RETURN lcRet
>
>ENDFUNC
>
>
>FUNCTION StrToLong(tlcLongstr)
> *!* Passed: 4-byte character string (lcLongstr) in low-high ASCII format
> *!* Returns: long integer value
> *!* Example:
> *!* m.longstr = "1111"
> *!* m.longval = strtolong(m.longstr)
>
> LOCAL lnI, lnRetval
>
> lnRetval = 0
>
> FOR lnI = 0 TO 24 STEP 8
> lnRetval = lnRetval + (ASC(tlcLongstr) * (2^lnI))
> tlcLongstr = RIGHT(tlcLongstr, LEN(tlcLongstr) - 1)
> NEXT
>
> RETURN lnRetval
>
>ENDFUNC
>
>HTH,
>Armin
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform