zoukankan
html css js c++ java
vb的GUID生成算法
源代码推荐:vb的GUID生成算法
'
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
((iDataLen
*
2
)
-
iStrLen,
"
0
"
) _
&
Trim
$(sPartTwo)
'
Next 4 Chars
sPartThree
=
Hex
$(udtGuid.PartThree)
iStrLen
=
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 = sPartOne & "-" & sPartTwo & "-" & sPartThree _
'
& "-" & sPartFour
sAns
=
sPartOne
&
sPartTwo
&
sPartThree
&
sPartFour
End
If
GUID
=
sAns
Exit
Function
errorhandler:
'
return a blank string if there's an error
Exit
Function
End Function
查看全文
相关阅读:
怎么修改android飞行模式wifi
斐讯n1盒子装远程迅雷
Spring使用大全
面向对象7大设计原则
Mybatis之SqlNode解析
【转载】MongoDB的C#驱动程序教程
【转载】 mongodb C# 基本类库
【转载】列举MongoDB C#驱动的几个Query方法
【转载】MongoDB开发学习
【转载】sql全国省市区数据库建表过程
原文地址:https://www.cnblogs.com/todd/p/104550.html
最新文章
Java 原生NIO
再看Spring
MongoDriver
Tomcat简介,希望能帮到你
零散的思考
软件升级的意义
代码整洁之道 读书笔记
c++错误
worknote
Linux进阶命令用法
热门文章
grep正则表达式
python基础知识
oracle之序列用法
Linux正则表达式练习
shell脚本练习
Linux shell编程语法
shell编程基础
交互式学习资源
使用shell脚本一键安装Nginx
linux之查找包含指定内容(字符串)的文件
Copyright © 2011-2022 走看看