Help with Visual basic?

gov78

Ha made you Look
OP
Member
Joined
Feb 14, 2007
Messages
727
Trophies
0
Age
32
Location
London
Website
Visit site
XP
351
Country
Hi guy basically i got a problem, im making a basic login program in vb and i need to implement a loop with the login program. Basically i was wondering if anyone has any idea of what type of loop i need and how i would implement this in to my code. The loop need do count how many times the enter a wrong password some thing like "You entered the password or username wrong you have 2 tries left" and i want it to do it 3 time and if failed close the program. Anyone got any clue of how to do this?

Thanks in advance

Here my code currently

Public Class Form1

Private Sub btnLogon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogon.Click
Dim NextForm As New Form2
If txtUser.Text = "admin" And txtPass.Text = "pass" Then
NextForm.Show()
Me.Hide()
End If
txtUser.Text = ""
txtPass.Text = ""


End Sub
End Class
 

murkurie

Well-Known Member
Member
Joined
Feb 16, 2010
Messages
316
Trophies
0
Age
30
Location
California, Redlands
XP
117
Country
United States
I would suggest using a while looping, that's the easiest way I can think of,
then if its wrong, have another popup come up and say you have this many tries left

while "variable for guesses"
 

evandixon

PMD Researcher
Developer
Joined
May 29, 2009
Messages
1,725
Trophies
0
Website
projectpokemon.org
XP
2,302
Country
United States
Public Class Form1
dim _trys as integer=0
Private Sub btnLogon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogon.Click
Const MaxTrys as integer = 3
If txtUser.Text = "admin" And txtPass.Text = "pass" Then
Dim NextForm As New Form2
NextForm.Show()
Me.Hide()
else
_trys+=1
If _tries >= MaxTrys Then
MessageBox.Show("You have entered an incorrect login or password " & MaxTrys.ToString & " or more times. Program will now close.")
Me.Close
Else
MessageBox.Show("You have entered an incorrect login or password. You have tried " & _trys.ToString & " time(s). You have " & (MaxTrys - _trys).ToString & " more trys left.")
End If
End If
txtUser.Text = ""
txtPass.Text = ""
End Sub
End Class


See if that works, because I don't think a loop is nessessary.
 

You may also like...

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3N1 @ K3N1: https://youtube.com/shorts/5_yMwLMHhjc?feature=share