BUG: Cursor Jumps Around when Typing in Edit Box

This article was previously published under Q207797
This article has been archived. It is offered "as is" and will no longer be updated.
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.
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.
Use the Text property rather than the Value property.
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
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

  1. Place the following code into a new program file:
    PUBLIC oform1oform1=CREATEOBJECT("form1")oform1.ShowRETURN	***************************************************-- Form:         form1*-- ParentClass:  form*-- BaseClass:    form*DEFINE CLASS form1 AS 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        ENDPROCENDDEFINE**-- EndDefine: form1**************************************************					
  2. Save and run the code.
  3. 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.
  4. Start typing the word Hello and watch where the letters end up.
  5. 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.
  6. Save and rerun the program. Repeat step 4 and note that the cursor no longer jumps around.

Article ID: 207797 - Last Review: 02/28/2014 04:17:12 - Revision: 1.1

  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 5.0a
  • Microsoft Visual FoxPro 6.0 Professional Edition
  • kbnosurvey kbarchive kbbug kbcodesnippet kbnofix kboop KB207797