Could someone please tell me how to write a password script in Visual Basic 6.0. I need to link a password form to another form so that if the password is entered correctly then it will open the linked form.
![]() |
Could someone please tell me how to write a password script in Visual Basic 6.0. I need to link a password form to another form so that if the password is entered correctly then it will open the linked form.
Well, the easiest way is to not have an extra password form, and just do it with an Input box when the main form loads, like this:
Private Sub Form_Load()
Dim strPass as String
StrPass = InputBox("Enter Password")
If strPass <> "Password" Then
MsgBox "Access denied"
End
End If
End Sub
(replace "Password" with whatever you want the password to be).
This pops up an input box before the form becomes visible, and if the password is wrong, it exits the program. This code doesn't have to be in the Form_Load() event necessarily, for instance if you wanted a form to display some graphics along with asking for a password (such as a title page), you could just add a panel to your main form, the size of the form itself, and make it visible when the program loads, so that the rest of the program is hidden, and include a text box and button on this panel, asking for a password. Then it's just a matter of using the above code (without the Input Box) to check the password and shut down.
If neither of these appraches are what you're looking for (ie if you reeeeeally have to have another form come up at the start ;)), post back and I'll dig up an example :)
All times are GMT -7. The time now is 01:06 AM. |