Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL and LOCATE IDENTICAL But get different results...
Message
From
26/05/2004 12:29:11
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
SQL and LOCATE IDENTICAL But get different results...
Miscellaneous
Thread ID:
00907422
Message ID:
00907422
Views:
55
I am building a 'lite' version of working, already released software in VFP 6. The released version has the same code used below and it works perfectly but i am currently getting far different results..the code is listed below.

The SQL statement creates a cursor with info for records that have matching SSN's. We expect to find a result of 0 records, 1 record, or unlikely more than one record. More than one record causes the problem. More than one record and you get a modal form with a choice of matching records. The modal form returns a value 'giappid' for the correct record. At the point of returning from the modal form, giappid is > 0 and using this value we attempt to LOCATE it in the crsCheck. This fails (crsCheck is at EOF) and all the subsequent replace statements are useless. Far below is the same code in the older "working' version. To make it even more crazy, if i switch the variable in the SQL statement from "applicnt.cssn = lcssn"
to "applicnt.cssn = lcssn2" which is a copy of lcssn before I format it for display, the code works fine. (note: that lcssn is not formatted until after the SQL statement) Also if i switch the SQL statement to
"ALLTRIM(applicnt.cssn) == ALLTRIM(lcssn)" it works.

My only concern is that there is an issue here that will become apparent in a released and possibly soon to be released software. I can make the code work but should i be worried about the released code? Maybe im just missing something simple..or im just too tired of looking at it.


Thanks in advance,

Mike
*****************************************************************************
***	Code:updates.pgf1.page3.grdforum.Column1.Text1.InteractiveChange()
***	Author:		
***	Date:		13 July 2001		
*****************************************************************************
LOCAL loForm, lcssn_lsac, lcssn, lclsac_id, lcssn2
loForm = .NULL.
lcssn_lsac = ''
lcssn = ''
lcssn2 = ''
lclsac_id = ''
lcssn_lsac = ALLTRIM(THIS.VALUE)

IF LEFT(lcssn_lsac,1) == 'L'
  **** it is an LSAC ID
  lclsac_id = lcssn_lsac
  lcssn = ''
ELSE
  *** We assume it is an SSN
  lclsac_id = ''
  lcssn = lcssn_lsac
  *** store an unformated copy of ssn
  lcssn2 = lcssn
ENDIF

IF LEN(ALLTRIM(THIS.VALUE)) < 9 
  *** OTHER VALIDATION
  RETURN
ENDIF

IF !EMPTY(lcssn)
  *** we are assuming this is an SSN!


**** This is the SQL Statement


  SELECT cfirstname, cmiddlename, clastname, cfindec, icurstat, iappid,
  dcreatedate FROM applicnt WHERE applicnt.cssn = lcssn AND !DELETED() ORDER
  BY iappid DESCENDING INTO CURSOR crscheck

  *** Now we convert lcssn to the correct format (999-99-9999)
  lcssn = LEFT(lcssn,3) + "-" + SUBSTR(lcssn,4,2) + "-" + RIGHT(lcssn,4)

  DO CASE
    CASE _TALLY = 1
      *** THIS WORKS

    CASE _TALLY = 0 AND setupall.lscode # "OTRA"
      *** THIS WORKS

    CASE _TALLY > 1
      IF !('RESOURCE' $ SET('CLASSLIB'))
        SET CLASSLIB TO resource ADDITIVE
      ENDIF

      SELECT crscheck
      LOCATE FOR .T.
      LOCAL loForm
      *** here we send the unformatted ssn to the object
      loForm = CREATEOBJECT('frmduplicatessn',lcssn2, crscheck.cfirstname,
      crscheck.clastname, Thisform)

      loForm.show()

      Thisform.pgf1.Page3.grd1.Setfocus()
				
      IF Thisform.giappid > 0

        SELECT crscheck


**** This is the point of failure



        LOCATE FOR crscheck.iappid = Thisform.giappid

        SELECT crssocial
        REPLACE cfirstname WITH crscheck.cfirstname
        REPLACE cmiddlename WITH crscheck.cmiddlename
        REPLACE clastname WITH crscheck.clastname
        REPLACE cfindec WITH crscheck.cfindec

        IF SEEK(crscheck.icurstat, "code", "icode")
          REPLACE ccurstat WITH CODE.ccodedesc
        ENDIF

        REPLACE iappid WITH crscheck.iappid
        REPLACE cssn_lsac WITH lcssn
        This.refresh()	

        KEYBOARD "{DNARROW}"

        THIS.PARENT.PARENT.REFRESH()

      ELSE

        REPLACE crssocial.cssn_lsac WITH SPACE(11)
        This.value = ''

      ENDIF

      loForm = .NULL.

      THIS.PARENT.PARENT.REFRESH()

    ENDCASE

ELSE





**** Old version ... it works

********************************************************************************  Code:updates.pgf1.page3.grdforum.Column1.Text1.InteractiveChange()
***  Author:		
***  Date:   13 July 2001		
*****************************************************************************LOCAL loForm, lcssn
loForm = .NULL.
lcssn = THIS.VALUE

IF LEN(ALLTRIM(THIS.VALUE)) < 9 
*** OTHER VALIDATION	
  RETURN
ENDIF

SELECT cfirstname, cmiddlename, clastname, cfindec, icurstat, iappid,
   dcreatedate FROM applicnt WHERE cssn = lcssn AND !DELETED() ORDER BY
   iappid DESCENDING INTO CURSOR crscheck

DO CASE

CASE _TALLY = 1
*** This works!

CASE _TALLY = 0 AND setupall.lscode # "OTRA"
*** This works!

CASE _TALLY > 1
*** This works!

IF !('RESOURCE' $ SET('CLASSLIB'))
SET CLASSLIB TO resource ADDITIVE
ENDIF

SELECT crscheck
LOCATE FOR .T.
LOCAL loForm

loForm = CREATEOBJECT('frmduplicatessn',lcssn, crscheck.cfirstname,
  crscheck.clastname, Thisform)

loForm.show()

Thisform.pgf1.Page3.grd1.Setfocus()
			
IF Thisform.giappid > 0

SELECT crscheck

LOCATE FOR crscheck.iappid = Thisform.giappid

SELECT crssocial
REPLACE cfirstname WITH crscheck.cfirstname
REPLACE cmiddlename WITH crscheck.cmiddlename
REPLACE clastname WITH crscheck.clastname
REPLACE cfindec WITH crscheck.cfindec

IF SEEK(crscheck.icurstat, "code", "icode")
REPLACE ccurstat WITH CODE.ccodedesc
ENDIF

REPLACE iappid WITH crscheck.iappid
KEYBOARD "{DNARROW}"

ELSE

REPLACE crssocial.cssn WITH SPACE(9)
This.value = ''

ENDIF

loForm = .NULL.

THIS.PARENT.PARENT.REFRESH()

ENDCASE
Next
Reply
Map
View

Click here to load this message in the networking platform