Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incrementing memvar

Status
Not open for further replies.

KDavie

Programmer
Feb 10, 2004
441
US
I am writing code for a login form that prompts the user for a user ID and password. I am trying to create an incrementing memvar that counts the number of times a user enters an incorrect password. If an incorrect password is entered 3 times, I want the application to close. Here is my code:

LOCAL cUserNumber, cPassword, cUserLevelID, nCount

USE ActSysData!User

cUserNumber = ThisForm.txtUserNumber.Value
cPassword = ThisForm.txtPassword.Value

**Check to make sure user entered a user number and password

IF ISBLANK(m.cUserNumber) OR ISBLANK(m.cPassword) THEN

MESSAGEBOX("Please enter a valid User Number and Password")
RETURN .F. && early exit

ELSE && Search table and make sure usernumber and password are valid
SET ORDER TO 3
SEEK m.cUserNumber
IF NOT FOUND() THEN
MESSAGEBOX("You have entered an invalid User Number")
ELSE && verify that password is correct
IF m.cPassword <> password then
nCount = nCount + 1
IF nCount >= 3 then
QUIT
ENDIF
MESSAGEBOX ("You have entered and invalid Password")
ThisForm.TxtPassword.value = ""
thisform.txtPassword.SetFocus
RETURN .F. && early exit
EndIF
ENDIF

ENDIF


The problem is with nCount. If I don't give it a value when I declare it I get a data-type mismatch error. If I do give it a value then everytime the code is run it resets the value back to it's original state. I've tried For...EndFor, but don't fully understand how to control it. For example
I tried:

FOR i = 1 to 3
IF i >= 3 then
QUIT
ENDIF
EXIT
ENDFOR

but it just keeps looping until 'i' does = 3 and then closes the application, even though the password is only entered incorrectly 1 time.

Thanks in advance for your help.

-Kevin
 
Set the nCount value to 0 right after you define it as a local variable with:

nCount = 0

Also, just so you know memvar means something else (from help):

MEMVAR
Specifies the variables or array from which data is copied to the current record. Data is transferred from the variable to the field that has the same name as the variable. The contents of a field are not replaced if a variable doesn't exist with the same name as the field.
 
I tried that before I asked for help. I think I figured it out though. I think it is a scope issue. I can't define the variable nCount in this block of code, because when the user enters the new password it creates a new variable called nCount and assigns the value of 0 to it. My solution was to create a Public variable in the init event of the form. Will this create problems in a multiuser enviroment?

Thanks for your help.

By the way, I don't know why I wrote 'memvar,' I guess I've been on my computer for too long (12 hours)!

-Kevin
 
KDavie said:
My solution was to create a Public variable in the init event...
rather than create a PUBLIC variable, add a new property to your form called .nCount and assign it a value of 0.


Thereafter increment the value of the property with :-
Code:
[COLOR=blue]THISFORM.nCount = THISFORM.nCount + 1[/color]


FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.com
PDFcommandertm.co.uk


 
Thank you Chris,

Good call on the property, now it works exactly how it is supposed to!


-Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top