2024年1月22日发(作者:)

用VB编写一个密码解锁界面

我也就是刚开始学VB语言,VB语言很强大,有别于其它语言,操作性很强,就是很富有创造性得电脑语言。

下面就是我瞧了两天书后编写得一个小程序:

功能就是能建立两个窗口,一个密码窗口,一个为修改密码窗口。当密码输入正确后才能打开或者做一些事情,点击修改密码跳往第二个界面,修改成功后以修改得密码为解锁密码。中间有错误提示与误操作提示。

①先建立一个小窗口,如下图:

帐号一得“textbox”编号为“text1”,后面一次类推,command指令为1。

②程序得编写

Text1:

初始帐号为“07823”,如果可以得话可以给加入更多得功能,比如记忆多个账户与多对密码之类得等等。

2、text2

3、command1

初始密码为“1234”,open函数可以打开文件,自己可以设置文件路径。

4、command2

跳往第二个界面,隐藏第一界面。

5、初始指令

6、全局变量

全局变量本界面可以修改、其它界面可以调用得变量。

②建立第二个窗口

Text得序号从上到下依次顺序排列,command得命令一次从左到右排列

③第二个窗口得程序编写

1、Text1:

Private Sub Text1_LostFocus()

Dim b As Integer

Dim pw_1 As String, pw_2 As String

pw_2 = Form1、m

pw_1 = Text1、Text

If pw_1 <> pw_2 Then

b = MsgBox("密码错误", 5 + vbExclamation, "错误提示")

End If

End Sub

2、text2:

Private Sub Text2_LostFocus()

If Text2、Text = "" Then

MsgBox "新密码不能为空"

End If

End Sub

3、text3:

Private Sub Text3_LostFocus()

If Text2、Text <> Text3、Text Then

MsgBox "两次输入密码不一样"

Text2、Text = ""

Text3、Text = ""

Text2、SetFocus

End If

End Sub

4、command1:

Private Sub Command1_Click()

If Text2、Text = Text3、Text Then

n = Text2、Text

End If

Text1、Text = ""

Text2、Text = ""

Text3、Text = ""

Form1、Show

Form2、Hide

End Sub

5、command2:

Private Sub Command2_Click()

Text1、Text = ""

Text2、Text = ""

Text3、Text = ""

Form1、Show

Form2、Hide

End Sub

初始设置(Form)

Private Sub Form_Load()

Text1、PasswordChar = "*"

Text1、Text = ""

Text2、PasswordChar = "*"

Text2、Text = ""

Text3、PasswordChar = "*"

Text3、Text = ""

End Sub

全局变量申明

Public n As String