Grids are from Venus, cursors are from Mars (Help!)  
Author Message
lil_isie





PostPosted: Visual FoxPro General, Grids are from Venus, cursors are from Mars (Help!) Top

Hey guys, long time,<br><br>I've been recently working on grids with cursors, and doing cursor transfer stuff. After some point in time during a function, one of the product IDs changes itself. I have figured out how it happens, but not why it happens. Below I will post the original code:
set exact on
SCAN
    WITH thisform.pftransact.pInvoices.grdInvoice
        .column1.text1.value = crsItems.barCode
        .column2.text1.value = crsItems.prodName
        .column3.text1.value = crsItems.quantity
    endwith
    SELECT crsTransaction
    UPDATE crsTransaction SET crsTransaction.prodID = crsItems.prodID,;
                        crsTransaction.price = crsItems.pricePerBox;
    WHERE alltrim(crsTransaction.itemName) = alltrim(crsItems.ProdName)
   
    APPEND BLANK
    SELECT crsItems
endscan
set exact off

The way you solve the problem is by removing the 'alltrim' from the WHERE clause. Now, this makes absolutely no sense to me; however, maybe it would to you guys.I have the answer, but now I just need the explanation.  



Visual FoxPro1  
 
 
Tamar E. Granor





PostPosted: Visual FoxPro General, Grids are from Venus, cursors are from Mars (Help!) Top

Sounds like perhaps you're running into VFP's partial string matching. By default in VFP, strings are matched to the end of the shorter string. Try making the "=" in the UPDATE command into "==" (that is, two equal signs, which means "exactly equals" and eliminates partial matches).

Tamar

 
 
CetinBasoz





PostPosted: Visual FoxPro General, Grids are from Venus, cursors are from Mars (Help!) Top

Set exact on has no effect on SQL. For SQL you need set ansi on instead. However as Tamar said already you can make it "set ansi" independant with ==. I think with alltrim() your intention was to remove trailing blanks (no space at left). If that's the case:

... where crsTransaction.ItemName == crsItems.ProdName