build a search function similar to Microsoft Help in Windows 95 
Author Message
 build a search function similar to Microsoft Help in Windows 95

I would like to build a search function with VB5 that scrolls through a
list as I key in letter by letter.  Similar to Microsoft Help in Windows
95  under Index



Sat, 02 Sep 2000 03:00:00 GMT  
 build a search function similar to Microsoft Help in Windows 95

Quote:

>I would like to build a search function with VB5 that scrolls through a
>list as I key in letter by letter.  Similar to Microsoft Help in Windows
>95  under Index

I've made a control that does the trick ... here is the rough outline/code
you could easily adapt it to your needs

on form of usercontrol:
------------------------------
tstIn = textbox to type in
lstList = listbox to show all items and follow what's been typed in textbox

some code :
-----------------

Private ChangeMode As Boolean
Private l As String

' ////////////////////////////////////////////////
' //  Events

Public Event Selection(ID As Long)

' ////////////////////////////////////////////////
' //  Usercontol

Private Sub UserControl_Resize()
    lstList.Top = 100
    lstList.Left = 100
    lstList.Width = UserControl.Width - 200
    lstList.Height = UserControl.Height - txtIn.Height - 300

    txtIn.Top = UserControl.Height - 100 - txtIn.Height
    txtIn.Left = 100
    txtIn.Width = UserControl.Width - 200
End Sub

' ////////////////////////////////////////////////
' //  LIST

Private Sub lstList_Click()
    txtIn.text = lstList.text
    txtIn.SelStart = 0
    txtIn.SelLength = Len(txtIn.text)
    txtIn.SetFocus
End Sub

Private Sub lstList_DblClick()
    RaiseEvent Selection(Left$(txtIn.text, InStr(1, txtIn.text, ".") - 1))
End Sub

' ////////////////////////////////////////////////
' //  TEXT

Private Function Find(text As String) As String
Dim x As Integer
Dim found As Boolean

    found = False
    While x < lstList.ListCount And Not found
        If Left$(Trim$(lstList.List(x)), Len(text)) = text Then
            found = True
        Else
            x = x + 1
        End If
    Wend
    If found Then
        Find = lstList.List(x) ' ), InStr(1, Trim$(lstList.List(x)), "."))
        lstList.Selected(x) = True
    Else
        Find = ""
    End If
End Function

Private Sub txtIn_Change()
    If Not ChangeMode Then
        'if numeric
        l = Len(txtIn.text)
        If l > 0 Then
            ChangeMode = True
            txtIn.text = Find(txtIn.text)
            If txtIn.text <> "" Then
                txtIn.SelStart = l
                txtIn.SelLength = Len(txtIn.text) - l
            End If
            ChangeMode = False
        End If
    End If
End Sub

Private Sub txtIn_KeyPress(KeyAscii As Integer)
Dim dummy As Long

    Select Case KeyAscii
    Case 8:         ' backspace not only deletes selection
        KeyAscii = 0
        txtIn.text = Left$(txtIn.text, (Len(txtIn.text) - txtIn.SelLength) -
1)
    Case 13:        ' return key = accept
        KeyAscii = 0
        If txtIn.text <> "" Then
            dummy = Left$(txtIn.text, InStr(1, txtIn.text, ".") - 1)
            txtIn.text = ""
            lstList.Selected(lstList.ListIndex) = False
            RaiseEvent Selection(dummy)
        End If
    End Select
End Sub

' ////////////////////////////////////////////////
' //  Methodes

Public Sub DummyFill(title As String)
' dummy filler to test ... it add 150 items to the list
    For x = 1 To 150
        lstList.AddItem Trim$(Str$(x) + ". " + title + " " + Str$(x))
    Next x
End Sub

-------------------------------------------------------------

'this is how I call it from a standard project :
Private Sub Form_Load()
    SelList1.DummyFill "some data"
End Sub

'and the event that I receive when a selection is made ..
Private Sub SelList1_Selection(ID As Long)
    'do something with the selected item ...
End Sub

It's not the final version, but it did what I needed up to that point ...
If you can optimize it, let me know, ... right now I'm working on other
parts of the whole program, so it wasn't my intention to have it written
perfectly, it just had to work :))
I remember I wanted to show the selected item always in the middle of the
lstList, and not at the bottom, so the user could also see the following
items ... etc.

Have fun, hope it helps ...

Christophe VG



Sun, 03 Sep 2000 03:00:00 GMT  
 build a search function similar to Microsoft Help in Windows 95

Quote:
>I would like to build a search function with VB5 that scrolls through a list

as I key in letter by letter.  Similar to Microsoft Help in Windows 95  under
Index

You can do this using API calls.  See Article ID Q154076 in
the MS Visual Basic Knowledge Base on the MS web site.



Thu, 07 Sep 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. build a search function similar to Microsoft Help in Windows 95

2. Build a search function similar to Microsoft Help in Windows 95

3. One of two functions doesn't function on Windows 95 (i does on Windows NT)

4. Help: API function PlgBlt() for Windows 95 ??

5. Visual Basic 6 run-times requires Windows 95 build 708 or later

6. How Do I Use Windows 95 In Built Cusors

7. Controls Similar To Microsoft Windows Explorer

8. Microsoft Windows 95 don't know calculation

9. Windows 95 B, Setup Wizard Issues Setup.EXE on Windows 95 A

10. Microsoft Windows 95 pop up menu

11. Interface to Microsoft Fax (Windows 95 )

12. Windows 95 B, Setup Wizard Issues Setup.EXE on Windows 95 A

 

 
Powered by phpBB® Forum Software