INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tips & Tricks

Interactive Search / Autocomplete in a Text Box by Imaginecorp
Posted: 4 Feb 07

This is an Oldie:

CODE

****** VFP9 with SP 1
Public oform1

oform1=Newobject("form1")
oform1.Show
Return


**************************************************
*-- Form:         form1 (\imaginecorp\form11.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   02/02/07 01:25:12 AM
*
Define Class form1 As Form


    Top = 3
    Left = 48
    Height = 100
    Width = 375
    DoCreate = .T.
    ShowTips = .T.
    Caption = "Auto Complete"
    Name = "Form1"


    Add Object command1 As CommandButton With ;
        Top = 67, ;
        Left = 278, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "Close", ;
        TabIndex = 2, ;
        Name = "Command1"


    Add Object label1 As Label With ;
        AutoSize = .T., ;
        Caption = "Company", ;
        Height = 17, ;
        Left = 60, ;
        Top = 25, ;
        Width = 55, ;
        TabIndex = 3, ;
        Name = "Label1"


    Add Object text1 As TextBox With ;
        Format = "K", ;
        Height = 23, ;
        Left = 120, ;
        SelectOnEntry = .T., ;
        TabIndex = 1, ;
        Top = 20, ;
        Width = 207, ;
        Name = "Text1"


    Procedure Load
        If Used("customer")
            Use In customer
        Endif
        **** Do not need to do this if there is an Index
        Set Exclusive On
        ************************************************
        Select 0
        Use Home()+"samples\data\customer.dbf"
        ************************************************
        Index On company Tag company
        Set Order To Tag company
        ************************************************
    Endproc


    Procedure command1.Click
        Thisform.Release
    Endproc


    Procedure text1.InteractiveChange
        With This
            If (Lastkey() >= 32 And Lastkey() <= 127)
                .nIDSelStart = Icase(.nIDSelStart >= 0 And Lastkey() = 127,.nIDSelStart - 1,;
                    .nIDSelStart < 0,0,;
                    .nIDSelStart + 1)
                Select customer
                coldtag = Tag()
                Set Order To Tag company
                Locate For Substr(Alltrim(Upper(customer.company)),1,.nIDSelStart) = ;
                    Upper(Substr(This.Value,1,.nIDSelStart))
                ***** Could use a SEEK() as well
                If  Found()
                    This.Value = customer.company
                Else
                    If !Empty(This.Value)
                        .nIDSelStart = This.SelStart
                    Else
                        .nIDSelStart = 0
                    Endif
                Endif
                This.SelStart = .nIDSelStart
                Set Order To Tag (coldtag)
            Endif
        Endwith
        This.SelLength = Iif(!Empty(This.Value),(Len(Alltrim(This.Value))-(This.nIDSelStart)),1)
    Endproc


    Procedure text1.Init
        If !Pemstatus(This,"nIDSelStart",5)
            This.AddProperty("nIDSelStart",0)
        Endif
    Endproc


Enddefine
*
*-- EndDefine: form1

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close