VB 密码设置问题

2024-11-21 22:24:53
推荐回答(3个)
回答1:

楼上是正确的。不过你混乱得可以了,两个窗口全办理~
(主程序)form1中:

Private Sub Form_Load()

If Dir("C:\text.ini") = "" Then '如果密码文档不存在,则调用form2设置密码
Form2.Show
Else’如果密码文档存在
Open "c:\text.ini" For Input As #1
Input #1, pass
Close #1
Do While InputBox("请输入密码", "密码验证") <> pass '直到密码正确,否则循环
MsgBox "密码不正确,请重新输入"
Loop
End If

End Sub

form2中(控件包括text1,text2,command1):
Private Sub Command1_Click()
If Text1.Text = Text2.Text And Text1.Text <> "" And Text2.Text <> "" Then
Open "c:\text.ini" For Output As #1
Print #1, Text1.Text
Close #1
Unload Me
Form1.Show
Else
MsgBox "密码不一样", 17, "重输入相同的密码"
Text1.SetFocus
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
MsgBox "为了安全,请尽早设置密码"
Form1.Show
End Sub

回答2:

dim pass as string
Open "c:\text.ini" For Input As #1
input #1,pass
close #1
现在pass里面就是你刚才保存的密码了

回答3:

Private Sub Command1_Click()
Open "c:\text.ini" For Input As #1
Input #1, a
Close #1
If Text1.Text = a Then
Form3.Visible = True
End If
End Sub