VB中如何实现动态密码保护、输出?

来源:百度知道 编辑:UC知道 时间:2024/04/30 13:18:46
以下是部分代码,请高手们帮忙看下。。。。
顺便提一句。。。我学VB才两天。。。所以可能错误很多。。还请见谅。。。

Private Sub Command1_Click()
Dim day As Integer
Dim month As Integer
Dim year As Integer
Dim pwda As Integer

day = today.getDay()
month = today.getMonth()
year = today.getYear()

If (month = 1) Then pwda = 976327
If (month = 2) Then pwda = 642538
If (month = 3) Then pwda = 544394
If (month = 4) Then pwda = 856032
If (month = 5) Then pwda = 157902
If (month = 6) Then pwda = 796320
If (month = 7) Then pwda = 386487
If (month = 8) Then pwda = 498865
If (month = 9) Then pwda = 264893
If (month = 10) Then pwda = 936954
If (month = 11) Then pwda = 765986
If (month = 12) Then pwda = 896327
End
End
End
End
End
End
End<

所有代码可以精简为

Private Sub Command1_Click()
Dim vDay, vMonth, vYear As Integer '声明年月日变量
Dim pwd, pwda As Long'声明密码变量

vDay = day(Now)'取日
vMonth = month(Now)'取月
vYear = year(Now)'取年
pwda = Choose(vMonth, 976327, 642538, 544394, 856032, 157902, 796320, 386487, 498865, 264893, 936954, 765986, 896327)'Choose赋值 注:vb妮可教偶D
pwd = pwda * vDay + vYear '运算
MsgBox pwd, vbOKOnly, "密码"'输出
End Sub

那么多end是做什么呀?
不需要啦
if...then...
这样一句就完了,后面不用end if了

Private Sub Command1_Click()
pwda = Array("976327", "642538", "544394", "856032", "157902", "796320", "386487", "498865", "264893", "936954", "765986", "896327")
password = pwda(Month(Now) - 1)
MsgBox "密码:" & password
End Sub