Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cant get home from endscan
Message
From
13/06/2013 10:41:16
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
12/06/2013 22:35:59
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01576184
Message ID:
01576252
Views:
49
>When i scan for a match and GET a match, i exit and assume the program should break out of the loop.
>what happens here however is that the program continues AFTER the endscan even if i place a RETURN
>
>so the only way i have found to determine if the scan was successful is to place a count in the search.
>
>i must be missing something. Can anyone tell me how to break out of the scan and return to the program that called the lookup procedure without the messy count.
>
>what i want is if the scan is successful in find one match to break out and not go beyond endscan. the only time endscan should be reached is if the scan was not successful in finding a match.
>
>tnx
>k
>
>
>procedure lookup
>cc=0
>scan for sct = TL  
>wait window tl+ " found '
>cc=cc+1
>exit
>RETURN	
>endscan
>		if cc = 0
>		WAIT WINDOW TL+' NOT FOUND '
>		endif
>


That code seems to say you want the first matching record only. That is the job of locate. Can you show what indexes you have on the table you are scanning?

PROCEDURE LookupTL
LPARAMETERS luTL
LOCAL llFound
LOCATE FOR sct = m.luTL
llFound = FOUND()
IF FOUND()
WAIT WINDOW m.luTL + 'FOUND'
ELSE
WAIT WINDOW m.luTL + 'NOT FOUND'
ENDIF
RETURN m.llFound

Good programming practice says that a routine should be passed what it needs. So I set up a local parameter m.luTL. The way your code is written, if there is a field called TL, it will use that value, even if you have a memory variable called TL. I don't like that kind of risk. Is sct a field in a table? It seems you are hoping this routine will work for different aliases as long as those aliases have an sct field? Lookup is not a good name for this, especially since there is a lookup function in FoxPro. Call it LookupTL to be more specific and different from the native lookup().

If it would be a problem to have the record point in the alias suddenly moved, you might also want to have this routine put the record pointer back where it was before the locate. If you are intending to use values from the found record, then this should be fine.
Previous
Reply
Map
View

Click here to load this message in the networking platform