Microsoft KB Archive/130299

= PRB: CURVAL Returns Same Value as OLDVAL =

Article ID: 130299

Article Last Modified on 2/15/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q130299



SYMPTOMS
Under certain circumstances, CURVAL and OLDVAL return the same value.



CAUSE
This is by design. CURVAL and OLDVAL only return different values when the following two conditions are both true:


 * Optimistic buffering is enabled.
 * Another user has modified the current record in a table while you were editing it.

In addition, CURVAL and OLDVAL return the same value if the all three of the following conditions are met:


 * Two forms in the same Visual FoxPro session are using the same table.
 * The data on one instance of the form has been modified.
 * The data on another instance of the form has not been modified.

In this case, CURVAL does not return a different value because the two instances of the forms share a data session by default. Because the user has locked the record in the first form, the data session in the second form considers itself to have locked the record as well.



RESOLUTION
Choose one of the following threee alternatives:

 If you want to write code to determine if the current user has modified the current record, use the GETFLDSTATE function. The GETFLDSTATE function returns a numeric value indicating if one or more fields in the current record have changed, if a record was appended, or if the deletion status of the current record has changed. For more information on using GETFLDSTATE, please see the Visual FoxPro Help file. -or-

 -or- If you want to test code in a multiuser scenario, you must have two data sessions running. To do this:

 Run two instances of Visual FoxPro simultaneously on the same or networked computers. -or-

 -or-Set the DataSession property of the form to 2 - Private Data Session, and run two instances of the form.

-or-

  -or- If you are using pessimistic buffering, or no buffering, change to optimistic row or table buffering by using the CURSORSETPROP function in the init method of the form. For example, enter the following command to set optimistic table buffering: =CURSORSETPROP("BUFFERING",5) </li></ul>

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Create a new form, and add a table to the data environment.</li> Drag at least one field from the data environment onto the form.</li>  Add a command button to the form. Set the caption of the button to Display. In the click event of the button, type the following code, substituting the field name from step 2 for. The field name should be enclosed in quotation marks: =MESSAGEBOX("Current value of field: " + CURVAL(<'fieldname'>) + ;              CHR(13) + ;              "Old value of field:      " + OLDVAL(<'fieldname'>)) </li>  Add a second command button to the form. Set the caption of the button to Update. In the click event of the button, type the following code: =TABLEUPDATE </li>  In the init event of the form, add the following code: =CURSORSETPROP("BUFFERING",5) </li> Save the form as TESTFORM.</li> In the Command window, type DO FORM TESTFORM and press ENTER. Repeat this step.</li> Move the forms so that you can see each form on the screen.</li> Change the data in one copy of the form, and press ENTER. Click the Display button. The current value and old value should be the same. Click the Update button.</li> Click the second copy of the form. Click the Display button. The current and old value should be the same.</li> Close both instances of the form. Change the form.DataSession property to 2, and run both copies of the form again. The curval and oldval functions should display the same value on the copy of the form in which you changed the data. After clicking the Update button in this copy of the form, the unmodified copy of the form should display different values for the curval and oldval functions.</li></ol>

Additional query words: VFoxWin multi-user

Keywords: vfoxwin kbnetwork 3.00 KB130299

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.