[Visual Basic] Source Code Recommended: VB's GUID Generation Algorithm

zhaozj2021-02-08  364

Recommended source: vb a GUID generation algorithm 'RETURNS: GUID if successful; blank string otherwise.'Unlike the GUIDS in the registry, this function returns GUID'without "-" characters See comments for how to modify if you'want the. dash.Public Function GUID () As String Dim lRetVal As Long Dim udtGuid As GUID Dim sPartOne As String Dim sPartTwo As String Dim sPartThree As String Dim sPartFour As String Dim iDataLen As Integer Dim iStrLen As Integer Dim iCtr As Integer Dim sAns As String On Error GoTo errorhandler sAns = "" lRetVal = CoCreateGuid (udtGuid) If lRetVal = 0 Then 'First 8 chars sPartOne = Hex $ (udtGuid.PartOne) iStrLen = Len (sPartOne) iDataLen = Len (udtGuid.PartOne) sPartOne = String (( Idatalen * 2) - Istrlen, "0") _ & Trim $ (spartone) 'Next 4 Chars sparttwo = hex $ (udtguid.parttwo) iStrlen = LEN (sparttwo) iDATALEN = LEN (UDTGUID.PARTTWO) sparttwo = String Idatal EN * 2) - Istrlen, "0") _ & Trim $ (sparttwo) 'Next 4 Chars Spartthree = HEX $ (UDTGUID.PARTTHREE) IDATLEN = LEN (Spartthree) iDatalen = LEN (UDTGUID.PARTTHREE) Spartthree = String Idatalen * 2) - Istrlen, "0") _ & Trim $ (spartthree) 'next 2 bytes (4 hex digits)' final 16 Chars for ictr = 0 to 7 spartfour = spartfour & _ format $ (HEX $ (UDTGUID. Partfour (ictr)), "00") Next 'to create Guid with "-", Change Line Below to:' Sans =

转载请注明原文地址:https://www.9cbs.com/read-743.html

New Post(0)