Search the Community
Showing results for tags 'guid isguid create'.
-
Check whether a GUID is valid. You may only need to copy one function only. Source: https://en.wikipedia.org/wiki/Guid Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsGUID ; Description ...: Check whether a GUID string is valid. ; Syntax ........: _IsGUID($sString) ; Parameters ....: $sString - Check a GUID string with or without brackets is valid. ; Return values .: Success: True ; Failure: False ; Author ........: guinness ; Remarks .......: SRE: http://mitchelsellers.com/blogs/2007/04/22/validating-a-guid-value-with-regular-expressions.aspx ; Example .......: Yes ; =============================================================================================================================== Func _IsGUID($sString) Return StringRegExp($sString, '^(?:(?<curly>\{)?[0-9A-Fa-f]{8}-(?:[0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}(?(curly)\}))$') > 0 EndFunc ;==>_IsGUIDFunction: (Different approach) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsGUID ; Description ...: Check whether a GUID string is valid. ; Syntax ........: _IsGUID($sString) ; Parameters ....: $sString - Check a GUID string with or without brackets is valid. ; Return values .: Success: True ; Failure: False ; Author ........: guinness ; Remarks .......: SRE: http://mitchelsellers.com/blogs/2007/04/22/validating-a-guid-value-with-regular-expressions.aspx ; Example .......: Yes ; =============================================================================================================================== Func _IsGUID($sString) Return StringRegExp($sString, '^(?:(?<curly>\{)?[[:xdigit:]]{8}-(?:[[:xdigit:]]{4}-){3}[[:xdigit:]]{12}(?(curly)\}))$') > 0 EndFunc ;==>_IsGUIDExample use of Function: Example() Func Example() Local $sGUID = CreateGUID() ; Or _WinAPI_CreateGUID() from WinAPIEx.au3. ConsoleWrite($sGUID & ': ' & _IsGUID($sGUID) & @CRLF) $sGUID = '{EBEB-642D-11E2-B009-B121}' ConsoleWrite($sGUID & ': ' & _IsGUID($sGUID) & @CRLF) $sGUID = '{E25F2E50-6497-11E2-BE9E-182679957A39}' ConsoleWrite($sGUID & ': ' & _IsGUID($sGUID) & @CRLF) $sGUID = 'EF3391DE-6497-11E2-B99A-182679957A39' ConsoleWrite($sGUID & ': ' & _IsGUID($sGUID) & @CRLF) EndFunc ;==>Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: CreateGUID ; Description ...: Create a valid GUID. ; Syntax ........: CreateGUID() ; Parameters ....: None ; Return values .: Success: GUID string ; Failure: Empty string and sets @error to non-zero ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func CreateGUID() ; Converted from a VBScript I had. Local $oTypeLib = ObjCreate('Scriptlet.TypeLib') If IsObj($oTypeLib) = 0 Then Return SetError(1, 0, '') EndIf Return StringLeft($oTypeLib.Guid, 38) EndFunc ;==>CreateGUID