Follow-up question to this: since it's already something not easily viewed (like an integer key would be), is there any reason to use STRCONV(MyGUID,x) to convert it to something else? I'm guessing STRCONV(MyGUID,15) might be better to view than it's original form. Not sure how many times I'd ever have to eyeball it (not that it would matter since I'm storing it in a variable anyway), so perhaps it's a moot point.

On 3/15/2013 9:29 AM, Dave Crozier wrote:
A guid generator here, no idea where I got it from though and it may even be 
the one on n2n.

Dave

* Generate GUID in VFP
clear

DO declare

  LOCAL cGUID, cGUIDString, cGUID1
cGUID = REPLICATE(CHR(0), 16)  && 128 bits

IF CoCreateGuid(@cGUID) = 0
     cGUIDString = StringFromGUID(cGUID)
     ? cGUID
     ? cGUIDString

     * converting from String back to GUID
     cGUID1 = REPLICATE(CHR(0), 16)
     = CLSIDFromString(STRCONV(cGUIDString,5), @cGUID1)
     ? cGUID1
ENDIF
* end of main
  return

FUNCTION StringFromGUID(cGUID)
     LOCAL cBuffer, nBufsize
     nBufsize=128
     cBuffer = REPLICATE(CHR(0), nBufsize*2)
     = StringFromGUID2(cGUID, @cBuffer, nBufsize)
     cBuffer = SUBSTR(cBuffer, 1, AT(CHR(0)+CHR(0), cBuffer))
RETURN STRCONV(cBuffer, 6)

PROCEDURE declare
     DECLARE INTEGER CoCreateGuid IN ole32 STRING @pguid

     DECLARE INTEGER CLSIDFromString IN ole32;
         STRING lpsz, STRING @pclsid

     DECLARE INTEGER StringFromGUID2 IN ole32;
         STRING rguid, STRING @lpsz, INTEGER cchMax


[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to