Microsoft KB Archive/207797

= BUG: Cursor Jumps Around when Typing in Edit Box =

Article ID: 207797

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q207797



SYMPTOMS
When you are inserting text in an edit box that already has data in it, the insertion point jumps through the existing data in an apparently random manner on each press of a key.



CAUSE
This is caused by referencing the Value property of the edit box during the InteractiveChange event when there are carriage return and line feed characters in the edit box data. Carriage return and line feed characters can get in the edit box when the ENTER key is pressed when typing in data.



RESOLUTION
Use the Text property rather than the Value property.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
The code below creates a form with an edit box on it. The Init method of the edit box assigns some text to the Value property, including carriage return and line feed characters.

Steps to Reproduce Behavior
  Place the following code into a new program file: PUBLIC oform1

oform1=CREATEOBJECT("form1") oform1.Show RETURN

************************************************** DEFINE CLASS form1 AS form
 * -- Form:        form1
 * -- ParentClass: form
 * -- BaseClass:   form

DoCreate = .T.       Caption = "Form1" Name = "FORM1"

ADD OBJECT edit1 AS editbox WITH ; Height = 169, ; Left = 120, ; Top = 24, ; Width = 145, ; Name = "Edit1"

PROCEDURE edit1.InteractiveChange x=This.Value *x=this.Text ENDPROC

PROCEDURE edit1.Init This.Value="" FOR i=1 TO 8 This.Value=This.Value+"Line "+ALLTRIM(STR(i))+CHR(13)+CHR(10) ENDFOR ENDPROC

ENDDEFINE
 * -- EndDefine: form1
 * -- EndDefine: form1

 Save and run the code. On line 4 of the edit box, click between the "e" in "Line 4" and the number 4. The insertion point should now be on line 4. Start typing the word Hello and watch where the letters end up. In Procedure Init in the code above, remove the asterisk (*) in front of the x=This.Text line and place it before the x=This.Value line.</li> Save and rerun the program. Repeat step 4 and note that the cursor no longer jumps around.</li></ol>

Keywords: kbbug kbnofix kboop kbcodesnippet KB207797

-

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

© Microsoft Corporation. All rights reserved.