6.3.1-唯一ID号生成¶
引言
本系统支持两种问题的标记,一种是尺寸,一种是颜色,分别用圆形和矩形表示。问题的位置事先是不知道的,所以默认将形状生成在固定位置,然后通过人工移动到需要位置,再将最新的位置保存即可。同时为了方便问题的管理,每个问题有一个唯一的ID号,是通过定义问题那一时刻的时间来生成的。
唯一ID号生成
代码如下
Function getUniqueId()
currentTime = Now()
uniqueId = Application.Text(currentTime, "yy-mm-dd hh:mm:ss")
uniqueId2 = Application.Substitute(uniqueId, "-", "")
uniqueId3 = Application.Substitute(uniqueId2, ":", "")
uniqueId4 = Application.Substitute(uniqueId3, " ", "")
getUniqueId = "id-" & CStr(uniqueId4)
Debug.Print (uniqueId4)
End Function
通过查看本地窗口中各变量的取值,如图6-4所示,可以知道每个函数的作用。一步步将时间转换为一个字符串,去除其中的符号和空格,只保留纯数字。
1)Now()获取当前的时间
2)Application.Text将时间数据类型转换为固定格式的字符串
3)Application.Substitute进行字符串替换
4)Cstr将数值型转换为字符串型
