CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 19

Threaded View

  1. #4
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: plz tell me error in my code

    First of all you can not stop/pause processing of loop by just issuing TextBox1.Focus(), Loop will continue. By Looking at ur code it can be understood that u want keep track of No of failed attempts made. So Keep a Counter to track it.

    The same code can be rewritten as below

    Code:
    Public Class Form1
        Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
            Dim STRUSER$
            Dim STRPASS$
            Static Attempts As Integer '<--- To keep track Attempts
            STRUSER = "ADMIN"
            STRPASS = "SUPER"
            If TextBox1.Text = STRUSER Or TextBox2.Text = STRPASS Then
                MsgBox("ACCEPTED")
                Me.Hide()
                Form2.Show()
                Exit Sub
            Else
                Attempts += 1
                If Attempts = 3 Then
                    MsgBox("UNAUTHORIZED USER....QUITING")
                    Me.Close()
                Else
                    MsgBox("INVALID USERNAME OR INVALID PASSWORD")
                    TextBox1.Text = ""
                    TextBox2.Text = ""
                    TextBox1.Focus()
                End If
            End If
        End Sub
    
    End Class
    This Works Fine.
    There is a bug in the above code. Can U Find It?
    Last edited by ComITSolutions; March 4th, 2008 at 10:45 PM.
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured