Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

VB6 help


Lenton
 Share

Recommended Posts

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 = False
Else
    MsgBox "wrong password! Try 1/3"
End If

txtpassword.Text = ""

If txtpassword.Text = "password" Then
    Form2.Visible = True
    Me.Visible = False
Else
    MsgBox "wrong password! Try 2/3"
End If

txtpassword.Text = ""

If txtpassword.Text = "password" Then
    Form2.Visible = True
    Me.Visible = False
Else
    MsgBox "wrong password! Try 3/3"
    End
End If

End Sub

When 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

SubPrivate Sub cmdlogin_Click()
Dim ctr as short
ctr = 0
If not txtpassword.Text = "password" And If Not ctr >=3 Then
ctr = ctr + 1
MsgBox " Wrong. Try " + ctr + "/3"
Else
    Form2.Visible = True
    Me.Visible = False
End If
Link to comment
Share on other sites

Sorry about typing that in a hurry  :embarrassed:

This is da code:

SubPrivate Sub cmdlogin_Click()
Dim ctr as integer
ctr = 0
If not txtpassword.Text = "password" And If Not ctr >=3 Then
ctr = ctr + 1
MsgBox " Wrong. Try " + ctr + "/3"
Else
    Form2.Visible = True
    Me.Visible = False
End If
End Sub

Damn Java , C++ and VB can cause some confusion :P
Link to comment
Share on other sites

  • 4 weeks later...
  • 2 weeks later...
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 = False
Else If Passwordtry = 0
    MsgBox "wrong password! Try 1/3"
Passwordtry = 1
End If

txtpassword.Text = ""

If txtpassword.Text = "password" Then
    Form2.Visible = True
    Me.Visible = False
Else If PasswordTry = 1
    MsgBox "wrong password! Try 2/3"
Passwordtry = 2
End If

txtpassword.Text = ""

If txtpassword.Text = "password" Then
    Form2.Visible = True
    Me.Visible = False
Else If Passwordtry = 2
    MsgBox "wrong password! Try 3/3"
MsgBox "This was your last try, the game will now close"
    Unload Me
End If

End Sub

```
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...