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
查看全文
相关阅读:
线性筛素数
m个苹果放入n个盘子问题
幸运的袋子
[HNOI2013]消毒
[SDOI2016]数字配对
[SCOI2015]小凸玩矩阵
[JLOI2008]将军
[HEOI2016/TJOI2016]游戏
[洛谷4329/COCI2006-2007#1] Bond
[BZOJ1324]Exca王者之剑
原文地址:https://www.cnblogs.com/todd/p/104550.html
最新文章
Struts2笔记1:--Struts2原理、优点、编程流程、6大配置文件以及核心配置文件struts.xml
局部内部类访问方法的参数和局部变量必须是final的
OpenJDK和JDK的区别
Redis 命令参考
centos6.5 升级python2.6到python2.7
centos6.5 安装jdk8
linux scp
linux 后台运行jar包
Warnings : Aggregation query used without partition key
WARN 02:04:10 Batch of prepared statements for [falcon_gps.gps] is of size 18000, exceeding specified threshold of 5120 by 12880.
热门文章
Java如何判断线程池所有任务是否执行完毕
Cassandra 总接归纳
java.lang.InterruptedException: sleep interrupted异常
Codeforces #369 (Div. 2) C. Coloring Trees (3维dp
一个数的 约数的个数 定理
逆序对(归并排
麦森数(分治或快速幂)
滑雪 ( bfs+记忆化
Codeforces Round #499(Div2) C. Fly (二分精度)
单词接龙
Copyright © 2011-2022 走看看