|
-
March 4th, 2008, 06:18 AM
#1
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.
-
March 4th, 2008, 07:11 AM
#2
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.
-
March 4th, 2008, 07:20 AM
#3
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.
-
March 4th, 2008, 10:28 AM
#4
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
-
March 4th, 2008, 11:07 AM
#5
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.
-
March 5th, 2008, 04:22 AM
#6
Re: plz tell me error in my code
I tried both suggetions bt not working
Thanks
-
March 5th, 2008, 04:26 AM
#7
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.
-
March 5th, 2008, 05:15 AM
#8
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
-
March 6th, 2008, 06:42 AM
#9
Re: plz tell me error in my code
 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.
-
March 6th, 2008, 06:51 AM
#10
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
-
March 6th, 2008, 07:16 AM
#11
Re: plz tell me error in my code
 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?
_
-
March 6th, 2008, 07:22 AM
#12
Re: plz tell me error in my code
 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-)
-
March 6th, 2008, 07:45 AM
#13
Re: plz tell me error in my code
Ok I will Give U Hint
Code:
Static Attempts As Integer '<--- To keep track Attempts
and
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
-
March 6th, 2008, 08:47 AM
#14
Re: plz tell me error in my code
 Originally Posted by ComITSolutions
Ok I will Give U Hint
Code:
Static Attempts As Integer '<--- To keep track Attempts
and
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.
-
March 6th, 2008, 08:55 AM
#15
Re: plz tell me error in my code
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|