Help with Visual basic?

Discussion in 'General Off-Topic Chat' started by gov78, Nov 24, 2010.

  1. gov78
    OP

    gov78 Ha made you Look

    Member
    2
    Feb 14, 2007
    London
    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

    Warning: Spoilers inside!
     
  2. murkurie

    murkurie GBAtemp Fan

    Member
    1
    Feb 16, 2010
    United States
    California, Redlands
    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

    Warning: Spoilers inside!
     
  3. gov78
    OP

    gov78 Ha made you Look

    Member
    2
    Feb 14, 2007
    London
    thanks for the info bud but thats C++ i belive
     
  4. evandixon

    evandixon PMD Researcher

    Member
    7
    May 29, 2009
    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.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice