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
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....
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....
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?
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.
Re: plz tell me error in my code
I tried both suggetions bt not working
Thanks
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.
Re: plz tell me error in my code
I dont think u read Post # 4
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
:D...
Re: plz tell me error in my code
NO!
It works fine( No problem with IF)! Bug is different
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?
_
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-)
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
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
Now Tell Me the Bug
HAHAHAHAHAHA....
I see it now...
Log out, and log back in, it does not reset to 3 chances. .... Hehehehe ...:lol:
But the If statement is also faulty, If only the user name is correct, wrong password, it will stil say Accepted.
Gremmy..
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?.
:)
Re: 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"
Hello all, I am taking VB.NET this semester and I was reading this code. I understand everytrhing except the first two variables. I uderstand they are a user and password what I dont understand is the following:
Why are they capitalized, why is there a $ at the end, and why are they not declared as anything. Sorry for the newb question but we have not come accross this yet.
can someone please fill me in thanks,
Rick
Re: plz tell me error in my code
The $ comes from old basic, (1980's basic) and is used for declaring the variable type as string... so is the same as
Code:
Dim STRUSER As String
The capitals is used as personal preferance and has no effect on the declarations..
Gremmy...
Re: plz tell me error in my code
These were supported in VB6, so I suppose .Net uses them.
Quote:
Program Constants
$ = String
% = Integer
& = Long
! = Single
# = Double
@ = Currency
No Boolean, Byte, Char, Date, Object, or Short!
Re: plz tell me error in my code