Click to See Complete Forum and Search --> : plz tell me error in my code
arsanl
March 4th, 2008, 05:18 AM
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
GremlinSA
March 4th, 2008, 06:11 AM
It whould help if you told us what its doing and not doing, What error you get Etc..
Also when posting Code please use Your Code Tags...
Gremmy....
GremlinSA
March 4th, 2008, 06:20 AM
After looking over the code briefly i noticed this..
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..
Dim VALID As Boolean
VALID = True
Do While Not VALID
I think this should correct the problem...
Gremmy....
ComITSolutions
March 4th, 2008, 09:28 AM
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
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?
HanneSThEGreaT
March 4th, 2008, 10:07 AM
arsanl, if you need proper precise help, you will need to state your question and errors properly, we are not mind - readers.
arsanl
March 5th, 2008, 03:22 AM
I tried both suggetions bt not working
Thanks
arsanl
March 5th, 2008, 03:26 AM
my error is that the code working bt it directly display msgbox 3 times after 1st attempt only.
ComITSolutions
March 5th, 2008, 04:15 AM
I dont think u read Post # 4
GremlinSA
March 6th, 2008, 05:42 AM
There is a bug in the above code. Can U Find It? The If statment, must be And and not Or
:D...
ComITSolutions
March 6th, 2008, 05:51 AM
NO!
It works fine( No problem with IF)! Bug is different
Marraco
March 6th, 2008, 06:16 AM
NO!
It works fine( No problem with IF)! Bug is differentThen you want to fire the msgbox("accepted") when the USERNAME OR the PASSWORD is not valid?
_
Marraco
March 6th, 2008, 06:22 AM
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-)
ComITSolutions
March 6th, 2008, 06:45 AM
Ok I will Give U Hint
Static Attempts As Integer '<--- To keep track Attempts
and
Me.Hide()
Now Tell Me the Bug
GremlinSA
March 6th, 2008, 07:47 AM
Ok I will Give U Hint
Static Attempts As Integer '<--- To keep track Attempts
and
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 ...:lol:
But the If statement is also faulty, If only the user name is correct, wrong password, it will stil say Accepted.
Gremmy..
ComITSolutions
March 6th, 2008, 07:55 AM
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?.
:)
RickyD
March 9th, 2008, 05:26 AM
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
GremlinSA
March 9th, 2008, 01:28 PM
The $ comes from old basic, (1980's basic) and is used for declaring the variable type as string... soDim STRUSER$ is the same asDim STRUSER As String
The capitals is used as personal preferance and has no effect on the declarations..
Gremmy...
dglienna
March 9th, 2008, 05:45 PM
These were supported in VB6, so I suppose .Net uses them.
Program Constants
$ = String
% = Integer
& = Long
! = Single
# = Double
@ = Currency
No Boolean, Byte, Char, Date, Object, or Short!
RickyD
March 9th, 2008, 11:40 PM
cool thanks guys!!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.