Help with Visual basic?

  • Thread starter Thread starter gov78
  • Start date Start date
  • Views Views 1,052
  • Replies Replies 3
  • Join the GBAtemp community: it's free
    • 50% fewer ads
    • Reply alerts
    • Join the discussion
    • Watch & bookmark

gov78

Ha made you Look
Member
Joined
Feb 14, 2007
Messages
727
Reaction score
0
Trophies
1
Age
36
Location
London
Website
Visit site
XP
421
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
 
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"
 
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.
 

Site & Scene News

New Hot Discussed User Submitted