PRB: SET DATE Resets SelStart Property in Text Boxes (313196)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 7.0
  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft Visual FoxPro for Windows 3.0b
  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a
  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q313196

SYMPTOMS

If you change the value of SET("DATE") while the focus is in a text box, the SelStart property is reset to 0, placing the insertion point before the first character. This occurs even if the form is in a different data session than the one in which you perform the SET DATE.

RESOLUTION

You can partially work around this behavior by saving and restoring the SelStart property in the routine that performs the SET DATE.
FOR i = 1 TO _SCREEN.FormCount
   loScreenForm = _SCREEN.Forms(i)
   IF TYPE("loScreenForm.ActiveControl.SelStart") = "N"
      loScreenForm.Tag = STR(loScreenForm.ActiveControl.SelStart)
   ENDIF
ENDfor

SET DATE TO (SET("DATE")) && This line will reset the SelStart property.

FOR i = 1 TO _SCREEN.FormCount
   loScreenForm = _SCREEN.Forms(i)
   IF TYPE("loScreenForm.ActiveControl.SelStart") = "N"
      loScreenForm.ActiveControl.SelStart = VAL(loScreenForm.Tag)
   ENDIF
ENDFOR
				

MORE INFORMATION

Steps to Reproduce Behavior

Run the following code to see the behavior in any version of Visual FoxPro:
PUBLIC oForm
oForm = CREATEOBJECT("Form")
oForm.Show()
oForm.AddObject("txtBox", "textbox")
oForm.txtBox.Visible = .T.

oForm.txtBox.SetFocus()
oForm.txtBox.Value = "12345"
oForm.txtBox.SelStart = LEN(oForm.txtBox.Value)
? oForm.txtBox.SelStart && will be 5

SET DATE TO (SET("DATE"))
? oForm.txtBox.SelStart && will be 0
				
NOTE: Although these examples all show the behavior within a form, you may also see this behavior when running a process from a timer that parses external data.

Modification Type:MajorLast Reviewed:5/12/2003
Keywords:kbBug kbCodeSnippet kbnofix kbprb KB313196