RT
谢谢大家,越快越好。

解决方案 »

  1.   

    Private Type GUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(7) As Byte
    End TypePrivate Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As LongPublic Function GetGUID() As String
    Dim udtGUID As GUIDIf (CoCreateGuid(udtGUID) = 0) Then    GetGUID = _
        String(8 - Len(Hex$(udtGUID.Data1)), "0") & Hex$(udtGUID.Data1) & _
        String(4 - Len(Hex$(udtGUID.Data2)), "0") & Hex$(udtGUID.Data2) & _
        String(4 - Len(Hex$(udtGUID.Data3)), "0") & Hex$(udtGUID.Data3) & _
        IIf((udtGUID.Data4(0) < &H10), "0", "") & Hex$(udtGUID.Data4(0)) & _
        IIf((udtGUID.Data4(1) < &H10), "0", "") & Hex$(udtGUID.Data4(1)) & _
        IIf((udtGUID.Data4(2) < &H10), "0", "") & Hex$(udtGUID.Data4(2)) & _
        IIf((udtGUID.Data4(3) < &H10), "0", "") & Hex$(udtGUID.Data4(3)) & _
        IIf((udtGUID.Data4(4) < &H10), "0", "") & Hex$(udtGUID.Data4(4)) & _
        IIf((udtGUID.Data4(5) < &H10), "0", "") & Hex$(udtGUID.Data4(5)) & _
        IIf((udtGUID.Data4(6) < &H10), "0", "") & Hex$(udtGUID.Data4(6)) & _
        IIf((udtGUID.Data4(7) < &H10), "0", "") & Hex$(udtGUID.Data4(7))
    End IfEnd FunctionPrivate Sub Command1_Click()
     MsgBox GetGUID
    End Sub
      

  2.   

    Option Explicit
    Public Type GUID
       Data1  As Long
       Data2  As Long
       Data3  As Long
       Data4(8)  As Byte
    End Type
    Private Declare Function CoCreateGuid Lib "ole32.dll" (pguid As GUID) As Long
    Private Declare Function StringFromGUID2 Lib "ole32.dll" (rguid As Any, ByVal 
    lpstrClsId As Long, ByVal cbMax As Long) As Long
     
    Public Function GUIDGen() As String
       Dim uGUID   As GUID
       Dim sGUID   As String
       Dim bGUID()   As Byte
       Dim lLen   As Long
       Dim RetVal   As Long
       lLen = 40
       bGUID = String(lLen, 0)
       CoCreateGuid uGUID   '把结构转换为一个可显示的字符串
       RetVal = StringFromGUID2(uGUID, VarPtr(bGUID(0)), lLen)
       sGUID = bGUID
       If (Asc(Mid$(sGUID, RetVal, 1)) = 0) Then RetVal = RetVal - 1
       GUIDGen = Left$(sGUID, RetVal)
    End Function'使用方法
    'Msgbox GUIDGen
      

  3.   

    'GUID是Globally  Unique  IDentifier的缩写.由一个特殊的算法来产生这些128位的数,
    '并保证不产生重复的GUID—重复的可能性当然存在,但有太多可用的数了,因此算法特别
    '防止产生重复的数,这种情况你一生都不会看到.