Lenton Posted August 2, 2008 Author Share Posted August 2, 2008 I'm a bit stuck on how to make this work. I'm just playing around with VB ATM to get the basics of it but now I'm stuck.What I'm trying to do is, if you enter a password and it's correct it opens up form2 but if you enter the wrong pass you get a message box appear. I want you to get 3 attempts and after all of them the program ends… This is what i got so far -Private Sub cmdlogin_Click()If txtpassword.Text = "password" Then Form2.Visible = True Me.Visible = FalseElse MsgBox "wrong password! Try 1/3"End Iftxtpassword.Text = ""If txtpassword.Text = "password" Then Form2.Visible = True Me.Visible = FalseElse MsgBox "wrong password! Try 2/3"End Iftxtpassword.Text = ""If txtpassword.Text = "password" Then Form2.Visible = True Me.Visible = FalseElse MsgBox "wrong password! Try 3/3" EndEnd IfEnd SubWhen i play this the msg box's keep showing in a row, is there anyway to pause it or whatever?Thanks in advance!EDIT: oops, this should have went in programing questions... Link to comment Share on other sites More sharing options...
vrage Posted August 2, 2008 Share Posted August 2, 2008 SubPrivate Sub cmdlogin_Click()Dim ctr as shortctr = 0If not txtpassword.Text = "password" And If Not ctr >=3 Thenctr = ctr + 1MsgBox " Wrong. Try " + ctr + "/3"Else Form2.Visible = True Me.Visible = FalseEnd If Link to comment Share on other sites More sharing options...
Lenton Posted August 2, 2008 Author Share Posted August 2, 2008 I get an error with this statement -If Not txtpassword.Text = "password" And **If** Not ctr >=3 Then Link to comment Share on other sites More sharing options...
Dark Crusade Posted August 2, 2008 Share Posted August 2, 2008 I'm no programmer, but I've never heard of an 'if not' statement. Wouldn't it be 'else'? Link to comment Share on other sites More sharing options...
Lenton Posted August 2, 2008 Author Share Posted August 2, 2008 No there is it's just un common and i fixed it -If Not txtpassword.Text = "password" And Not ctr >=3 ThenThere should only be 1 If at start.But now i get error on this -Dim ctr as short What should the short be? Link to comment Share on other sites More sharing options...
vrage Posted August 2, 2008 Share Posted August 2, 2008 Sorry about typing that in a hurry :embarrassed:This is da code:SubPrivate Sub cmdlogin_Click()Dim ctr as integerctr = 0If not txtpassword.Text = "password" And If Not ctr >=3 Thenctr = ctr + 1MsgBox " Wrong. Try " + ctr + "/3"Else Form2.Visible = True Me.Visible = FalseEnd IfEnd SubDamn Java , C++ and VB can cause some confusion :P Link to comment Share on other sites More sharing options...
Lenton Posted August 2, 2008 Author Share Posted August 2, 2008 Still not working many errors…This line does not work -If not txtpassword.Text = "password" And **If** Not ctr >=3 Then Link to comment Share on other sites More sharing options...
DrNova Posted August 28, 2008 Share Posted August 28, 2008 TryIf not txtpassword.Text = "password" And Not ctr >=3 Then?Just removed the second if, since the First if (should?) be sufficient?Worth a shot anyways Link to comment Share on other sites More sharing options...
vrage Posted September 6, 2008 Share Posted September 6, 2008 use 2 lines and 2 end ifsIf not txtpassword.Text = "password" ThenIf Not ctr >=3 ThenCode–----End IfEnd If Link to comment Share on other sites More sharing options...
anasky Posted September 13, 2008 Share Posted September 13, 2008 Haven't tested the following, but it should work:Place this on top of form1:```Dim Passwordtry As Integer```Then you place your own code with my edits, placed below:```Private Sub cmdlogin_Click()If txtpassword.Text = "password" Then Form2.Visible = True Me.Visible = FalseElse If Passwordtry = 0 MsgBox "wrong password! Try 1/3"Passwordtry = 1End Iftxtpassword.Text = ""If txtpassword.Text = "password" Then Form2.Visible = True Me.Visible = FalseElse If PasswordTry = 1 MsgBox "wrong password! Try 2/3"Passwordtry = 2End Iftxtpassword.Text = ""If txtpassword.Text = "password" Then Form2.Visible = True Me.Visible = FalseElse If Passwordtry = 2 MsgBox "wrong password! Try 3/3"MsgBox "This was your last try, the game will now close" Unload MeEnd IfEnd Sub``` Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now