how to do vb Login 3 TIMEOut?

December 10, 2012 at 16:37:12
Specs: Windows 7
hi ,
i am just trying to do a simple login with a 3 Warning of incorrect password then quit the program else the program will give him msg or move him to the other form i did some coding but i am sure it way from the right and this is my code:
Dim counter As Integer = 0
Dim pass As Boolean = False
Do Until counter = 3
If txtPassword.Text <> "123" Then
counter = counter + 1
pass = False
End If
Loop
If pass = False Then
MsgBox("Wrong password")
If counter = 3 Then
End
End If
Else
pass = True
MsgBox("correct")
End If

so if any one can help with this code i will appreciate it thanx in advance ^^


See More: how to do vb Login 3 TIMEOut?

Report •


#1
December 10, 2012 at 22:14:56
You should not assign value to a variable in the Dim Statements

You Dim the variables and then assign the values. What you are trying to do can only be one with constants.

However in this instance is is unnecessary. Counter will get the value of 0 every time the code runs and pass will default to false.

You should try re-writing the code so that if the user enters the correct password, pass is assigned True and test on that. Would make it a lot simpler. Testing an a default value is always fraught with problems.

You should never end a VB application with End. IIt will not terminate the application properly and will lead to memory leaks. End is only there for backward compatibility with earlier versions of VB.

In this instance, I take it the txtPassword.Text is on a form. To terminate the application, close the form. When the application reaches the end of the code in the current function, it will end. Using End and the form remains in memory taking up space

Stuart


Report •

#2
December 11, 2012 at 08:23:57
StuartS: You Dim the variables and then assign the values. What you are trying to do can only be one with constants.
This is no longer true. In fact, assigning a value when you Dim a variable is required for Option Infer to work correctly. Welcome to .NET; it's better here.

StuartS: You should never end a VB application with End. It will not terminate the application properly and will lead to memory leaks.
While I get where you're coming from, modern OS's are pretty good when it comes up to cleaning up after crashed programs. Leaked user mode known resources are reclaimed by the OS when the application's environment is torn down.

silent92:
You should avoid using either Application.Exit or Environment.Exit (aka VB's End) during the course of your application. Instead, you should restructure your flow to handle a failed logon without forcibly ending your application. That said, Application.Exit is better than Environment.Exit (or using End), as the relevant FormClosing, FormClosed, and Dispose events are raised. Environment.Exit (and End) don't raise any events, so your application can't clean up after itself.

How To Ask Questions The Smart Way


Report •

Related Solutions


Ask Question