Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autocomplete within Edit Object? 2

Status
Not open for further replies.

pt777

Technical User
Mar 27, 2004
62
US
I'm trying to program an *autocomplete* (for medical terms) with an Edit Object (Memo field); its getting tricky.

Any suggestions are appreciated in advance.

Ideally, we'd be able to:

(1) Start typing in a word and it finishes the word, to *stuff* it in the paragraph.

Currently I'm using the keypress event with code like:

Do Case
Case (Between(nKeyCode, 65, 90) Or Between(nKeyCode, 97, 122) Or Between(nKeyCode, 48, 57) )
pSearchstring = pSearchstring + Chr(nKeyCode) &&not proper for now
OTHERWISE
Release pSearchstring,pStart,pnCharactersReplaced,pNo,pOriginalValue,pReplacementName
Return
Endcase
If !Empty(pSearchstring)
lFound=Indexseek(pSearchstring,.F.,"visit","last_name")
=Indexseek(pSearchstring,lFound,"visit","last_name")
Endif
pReplacementName[pNo]=Iif(lFound,Alltrim(visit.last_name),pSearchstring) &&for now
IF lFound
lnCharsReplaced=lStart-pStart+1+Iif(pNo>1,Len(pReplacementName[pNo-1]),0) &&If pNo>=2 &&must discard the prior pReplacement, 1st
ELSE
lnCharsReplaced=lStart-pStart+1+Iif(pNo>1,Len(pReplacementName[pNo-1]),0) &&If pNo>=2 &&must discard the prior pReplacement, 1st
* return
ENDIF
NODEFAULT
This.Value=Stuff(This.Value,IIF(lfound,pStart,lStart),lnCharsReplaced,pReplacementName[pNo])
This.SelLength = IIF(lFound,Len(pReplacementName[pNo]),0) &&(this.Value)

 
Couple of possible approaches:

If you have VFP 9, consider implementing Intellisense. This works well, but the trouble is it only works with the native memo editor.

For a different approach, see my article "Speed Up Text Entry", in FoxPro Advisor, July 2003 ( This shows how to add standard phrases to a context menu, which is perhaps not as slick as using keystrokes to trigger the text entry, but my users all liked it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Mike,

Your "Insert Prase" Form to "Speed Up Text Entry" seems a valuable workaround, especially for discrete phrases and/or complex-spelled words. I may have to succomb to it at this point.

I'll have to study Intellisense, as to its feasibility (if any) in a user environment. I thought it was limited to (ie. VFP9) command and code windows.

(Note: As always, I'm extremely thankful for your responses)
 

Pt,

I'll have to study Intellisense, as to its feasibility (if any) in a user environment. I thought it was limited to (ie. VFP9) command and code windows.

That's true in VFP 7 and 8. In 9, Microsoft extended it to work with user-specified phrases, but, as I mentioned earlier, only in the memo editor. Like you, I prefer to give my users a proper edit box rather than the native memo editor, which is why I have never taken advantage of Intellisense for end users.

If you do decide to use my "insert phrase" technique, I'd be interested to hear your feedback. Your users might prefer a more keyboard-oriented approach, but -- as you have found -- it is quite tricky to implement it.

Thanks for the star.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
After *hard thought*, Using your "Insert Phrase" short menu program (with its additional adhoc flexibility) seems the best starting point.

It may still become tricky to use keypress and/or Interactive Change events to slicken entries: E.g.,
(1) To search 'your phrases'/invoke your shortmenu ... during keypress events/interactive changes ... Then
(2) ... To bypass your shortmenu when keypresses are continued (as might Intellisense,listboxes)
(3) To jump to the submenu phrase during keypress (as does Intellisense), etc.

Intellisense would not seem feasible (even for native memo windows) because:
(1) Intellisense (aka 'Syntax Coloring') seems to require Word-Wrap to be turned off. Most users would eschew that.
(2) *Floating* 'Native windows' are tricky.
(3) Intellisense programs themselves are tricky.

Perhaps, AutoComplete classes and/or ActiveX Controls will become more a viable technology for edit (vs text) fields.
 
I'm trying to program an *autocomplete* (for medical terms) with an Edit Object (Memo field); its getting tricky.

Andy and I wrote a column in the July 2004 KitBox column in Foxtalk magazine called "Tiy auto complete your edit boxes" that you may find useful:

Textbox Auto Completion, introduced in VFP 9.0, is very cool but works only for the Textbox control. However, there are many other scenarios where an auto-text feature would add great value to an application. In this month’s column, Andy and Marcia show how you can implement similar functionality for Editboxes, both in VFP 9.0 and in earlier versions of VFP.

Like Mike's, our class populates a context sensitive menu with commonly used phrases and allows you to add new ones on the fly.



Marcia G. Akins
 
To Mike and Marcia (and Andy):

Marcia I found it on MSDN July 04 ( and am studying this excellent piece to try to combine it with Mike's.

I've started with Mike's menu list controls and table (which are quite similar to yours) and (over the weekend) made Mike's look somewhat 'Intellisense-like' in *myEditControls* (as a TitleBar-Off form with paged-lists.

I felt it best to excise out Mike's cumbersome shortmenus (for the same reasons that you explained in your MSDN article) and keep his powerful paged-lists concept.

I'll strive to implement Marsha's "Ad Selected Text" feature (vs. my own browse command button) to add text fragments.

Mike and Marcia, though popular, right-clicking seems a less-than-optimal trigger for inserting text fragments.

Intellisense, text.autoComplete, and/or Winword seem to trigger *keypress events/searches*.
 

Pt777,

Mike and Marcia, though popular, right-clicking seems a less-than-optimal trigger for inserting text fragments.

Even though I implemented the right-click menu idea myself, I have to agree with you. I did it for the reasons I explained in my article (basically, because the users wanted it). But personally I would find a keyboard-driven approach more convenient.

Let us know how you get along with the way you are doing it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top