CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Mar 2008
    Posts
    3

    Unhappy plz tell me error in my code

    Code:
    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
            Dim STRUSER$
            Dim STRPASS$
            STRUSER = "ADMIN"
            STRPASS = "SUPER"
            Dim INTCTR As Integer
            INTCTR = 0
            Dim VALID As Boolean
            Do While Not VALID
                If TextBox1.Text = STRUSER Or TextBox2.Text = STRPASS Then
                    MsgBox("ACCEPTED")
                    Me.Hide()
                    Form2.Show()
                    Exit Do
                Else
                    VALID = False
                    INTCTR += 1
                    If INTCTR = 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
            Loop
        End Sub
    Last edited by HanneSThEGreaT; March 4th, 2008 at 09:50 AM.

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: plz tell me error in my code

    It whould help if you told us what its doing and not doing, What error you get Etc..

    Also when posting Code please use [Code] Your Code[/Code] Tags...

    Gremmy....
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: plz tell me error in my code

    After looking over the code briefly i noticed this..
    Code:
        Dim VALID As Boolean
        Do While Not VALID
    VALID is assumed to be false after been initiated, and is better to set it to true before checking..
    Code:
        Dim VALID As Boolean
        VALID = True
        Do While Not VALID
    I think this should correct the problem...

    Gremmy....
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  4. #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

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: plz tell me error in my code

    arsanl, if you need proper precise help, you will need to state your question and errors properly, we are not mind - readers.

  6. #6
    Join Date
    Mar 2008
    Posts
    3

    Unhappy Re: plz tell me error in my code

    I tried both suggetions bt not working
    Thanks

  7. #7
    Join Date
    Mar 2008
    Posts
    3

    Re: plz tell me error in my code

    my error is that the code working bt it directly display msgbox 3 times after 1st attempt only.

  8. #8
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: plz tell me error in my code

    I dont think u read Post # 4
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

  9. #9
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: plz tell me error in my code

    Quote Originally Posted by ComITSolutions
    There is a bug in the above code. Can U Find It?
    The If statment, must be And and not Or

    ...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  10. #10
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: plz tell me error in my code

    NO!

    It works fine( No problem with IF)! Bug is different
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

  11. #11
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: plz tell me error in my code

    Quote Originally Posted by ComITSolutions
    NO!

    It works fine( No problem with IF)! Bug is different
    Then you want to fire the msgbox("accepted") when the USERNAME OR the PASSWORD is not valid?
    _

  12. #12
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: plz tell me error in my code

    Quote Originally Posted by arsanl
    Code:
    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
            Dim STRUSER$
            Dim STRPASS$
            STRUSER = "ADMIN"
            STRPASS = "SUPER"
            Dim INTCTR As Integer
            INTCTR = 0
            Dim VALID As Boolean
            Do While Not VALID
                If TextBox1.Text = STRUSER Or TextBox2.Text = STRPASS Then
                    MsgBox("ACCEPTED")
                    Me.Hide()
                    Form2.Show()
                    Exit Do
                Else
                    VALID = False
                    INTCTR += 1
                    If INTCTR = 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
            Loop
        End Sub
    A question:
    TextBox1 and TextBox2 are on Form2?
    (in your code, they must reside on Form1 -I mean the form that holds your posted Sub-)

  13. #13
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: plz tell me error in my code

    Ok I will Give U Hint
    Code:
            Static Attempts As Integer '<--- To keep track Attempts
    and
    Code:
                    Me.Hide()
    Now Tell Me the Bug
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

  14. #14
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: plz tell me error in my code

    Quote Originally Posted by ComITSolutions
    Ok I will Give U Hint
    Code:
            Static Attempts As Integer '<--- To keep track Attempts
    and
    Code:
                    Me.Hide()
    Now Tell Me the Bug
    HAHAHAHAHAHA....

    I see it now...

    Log out, and log back in, it does not reset to 3 chances. .... Hehehehe ...

    But the If statement is also faulty, If only the user name is correct, wrong password, it will stil say Accepted.


    Gremmy..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  15. #15
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: plz tell me error in my code

    Quote Originally Posted by GremlinSA
    But the If statement is also faulty, If only the user name is correct, wrong password, it will stil say Accepted.
    Gremmy..
    that Logic is not derived by me. It was there in the first post, I just made the required chages. Who knows the original author's requirement is like that?.
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

Page 1 of 2 12 LastLast

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