算用户名和密码
上一篇 /
下一篇 2008-11-12 15:42:17
/ 个人分类:Excel VBA
Sub Macro1()
'
' Macro1 Macro
ActiveSheet.Range("C4") = ""
ActiveSheet.Range("C5") = ""
Dim str As String
str = ActiveSheet.Range("C3").Value
str = Format(str, "d/m/yy h:mm:ss")
If IsDate(str) = False Then
MsgBox ("Please enter an date expression like 'd/m/yy h:mm:ss' in C3.")
Exit Sub
End If
splitStr = Split(str, " ")
myDate = splitStr(0)
myTime = splitStr(1)
arrTime = getArr(myTime, ":")
myUB = UBound(arrTime)
For j = 0 To myUB
sumTime = sumTime + arrTime(j)
Next j
userName = "0x" & sumTime
'Debug.Print userName
ActiveSheet.Range("C4") = userName
arrDate = getArr(myDate, "/")
myUB = UBound(arrDate)
For k = 0 To myUB - 1
sumDate = arrDate(k) * arrDate(k + 1)
dateStr = dateStr & sumDate
Next k
password = "0x" & dateStr
'Debug.Print password
ActiveSheet.Range("C5") = password
End Sub
Function getX(ByVal x)
getX = x \ 10
End Function
Function getY(ByVal y)
getY = y Mod 10
End Function
Function getArr(ByVal strVal, ByVal delimiter)
splitString = Split(strVal, delimiter)
myUB = UBound(splitString)
Dim arrayStr() As Integer
num = 0
For i = 0 To myUB
MyStr = splitString(i)
If getX(MyStr) <> 0 Then
ReDim Preserve arrayStr(num)
arrayStr(num) = getX(MyStr)
num = num + 1
End If
ReDim Preserve arrayStr(num)
arrayStr(num) = getY(MyStr)
num = num + 1
Next i
getArr = arrayStr
End Function
收藏
举报
TAG: