<% ' =========================================== ' ASP获取GUID,有可选生成形式 ' 并返回处理后的结果 ' 例子: ' Dim guid ' guid = getGUID(0) '系统默认形式(40位,大写形式) ' guid = getGUID("36") '不含{}号(大写形式) ' guid = getGUID("32:L") '不含{}及-号,小写形式 ' guid = getGUID("34:U") '不含-号,大写形式 ' =========================================== ' 参数如下: ' sOption :生成的格式设置,格式为"length:case",系统生成的为40位带{,},-的格式的大写形式 ' length可指定为36,34,32则分别代表去除{},去除-,去除{}- ' case可指定大小写形式,可以是U代表大写形式,L代表小写形式 Function getGUID(ByVal sOption) On Error Resume Next 'Raise 1 sOption = Trim(""&sOption) Dim sTmp,oGUID Set oGUID = CreateObject("Scriptle"&"t.T"&"ypeLib") ' 系统缺少或禁止Scriptlet.TypeLib组件时(采用模拟时间串+随机数字字母) If 0<> Err Then Err.Clear Dim strSeed, seedLength, pos, Str, i,NowNums,tmpNow tmpNow = 10^10*Year(Now)+10^8*Month(Now)+10^6*Day(Now)+10^4*Hour(Now)+10^2*Minute(Now)+10^0*Second(Now) NowNums = tmpNow strSeed = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" seedLength = Len(strSeed) Str = "" Randomize For i = 1 To 18 Str = Str & Mid(strSeed, Int(seedLength * Rnd) + 1, 1) Select Case Left(sOption, 2) Case "36" ' 不包含{号和}号 If i=2 Then NowNums = Left(tmpNow,8)& "-" & Mid(tmpNow,9,4)&"-" & Right(tmpNow,2) If i=2 Or i=6 Then Str = Str & "-" Case "34" ' 不包含-号 Case "32" ' 不包含{,},-号 Case Else If i=2 Then NowNums = Left(tmpNow,8)& "-" & Mid(tmpNow,9,4)&"-" & Right(tmpNow,2) If i=2 Or i=6 Then Str = Str & "-" End Select Next getGUID = NowNums&Str Select Case Left(sOption, 2) Case "36" ' 不包含{号和}号 Case "34" ' 不包含-号 getGUID = "{" & getGUID & "}" Case "32" ' 不包含{,},-号 Case Else getGUID = "{" & getGUID & "}" End Select Exit Function End If sTmp = Trim(oGUID.Guid) Set oGUID = Nothing Select Case Left(sOption, 2) Case "36" ' 不包含{号和}号 sTmp = Mid(sTmp, Instr(sTmp,"{")+1, 36) Case "34" ' 不包含-号 sTmp = Replace(sTmp, "-", "") Case "32" ' 不包含{,},-号 sTmp = Mid(sTmp, Instr(sTmp,"{")+1, 36) sTmp = Replace(sTmp, "-", "") Case Else ' sth. to do... End Select '处理其它可选项 If Len(sOption) > 1 And Instr(sOption,":") > 0 Then sOption = Split(sOption, ":") ' 处理大小写形式 Select Case UCase(Trim(""&sOption(1))) Case "U" sTmp = UCase(sTmp) Case "L" sTmp = LCase(sTmp) Case Else ' sth. to do... End Select End If getGUID = sTmp End Function %>