'Help-Find'-style interface for vb4 programmed database search 
Author Message
 'Help-Find'-style interface for vb4 programmed database search

hello,

I wonder if anyone can help me with the following.
I'm trying to write a vb4 interface to provide my quite complex and
extremely relational access2 database with the necessary data.

The actual question is if anyone knows how to write a search interface
that resembles the Help-Find interface in almost all win95 apps; i.e.
a combination of a textbox and a listbox (see what i mean?).
The list to be searched contains more than 1000 person/band names.

In fact I managed to create such a thing, and it works (!),  but it
works extremely slow.

According to me, this is why:
the name-list that has to be searched is in fact a union query that is
saved in the db. This query unites three tables ('Bands', 'Persons',
'Aliasses') and results in a huge list of names. So, when I type a
character in the textbox, my program opens the query and performs a
'LIKE'-query on it. With every extra character I add, the program goes
through the same routine, and thus takes the huge union query to do
its search.
Isn't there a faster way to do this?
Can't vb temporarily load the list resulting from typing the first
character into the textbox, and take this temporary table as a (new)
basis for the search routine when typing a second character in the
textbox?

Anyway, I hope I'm not talking Chinese (it's Flemish in fact...)


or via this newsgroup.

Thanks a lot.




Fri, 28 Jul 2000 03:00:00 GMT  
 'Help-Find'-style interface for vb4 programmed database search

Is there any need to restrict the records?  Why not just search down through
the list and when you find an item who's start is the characters typed into
the box, make that item the selected item.  If an item wasn't found, leave
the selection where it is.

You would have a slight delay the first type a character was typed, if it
was somethign like "z", but after that, the records should be within
reasonable distance from the current selection.

For example:
Text box: Text1
List box List1

Sub CheckList
Dim intI as Integer, intLength as Integer
Dim strSearch as String

strSearch = Text1.Text
intLength = Len(strSearch)

With List1
    For intI = 0 to (.ListCount - 1)
        If Left$(.List(intI), intLength) = strSearch then
            .Selected(intI) = True
            Exit For
        End if
    Next intI
End With

This may be a bit faster.

Just my $.001
Jared White
Software Consultant/Developer
Orange, TX



Fri, 28 Jul 2000 03:00:00 GMT  
 'Help-Find'-style interface for vb4 programmed database search

Hey friend,

Try this:

Place a combo box (Style = 2) and a text box on a new form.
Place the text box directly over the textbox part of the combo box.

Drop this in the General Declarations section of the form:

Private Declare Function SendMessageByNum Lib "User" Alias "SendMessage"
_
(ByVal hWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam&) As Long
Private Declare Function SendMessageByString Lib "User" Alias
"SendMessage" _
(ByVal hWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam$) As Long

Now drop this in the Text1_Change event:

Const WM_USER = &H400
Const CB_FINDSTRING = (WM_USER + 12)
Const CB_SETCURSEL = (WM_USER + 14)
Const CB_SHOWDROPDOWN = (WM_USER + 15)
Dim StringPos As Long, Result As Long

      StringPos = SendMessageByString&(Combo1.hWnd, CB_FINDSTRING, 0,
Text1)
      If (StringPos >= 0) Then
         Result = SendMessageByNum(Combo1.hWnd, CB_SETCURSEL,
CInt(StringPos), 0)
         Result = SendMessageByNum(Combo1.hWnd, CB_SHOWDROPDOWN, True,
0)
      ElseIf Text1 = "" Then
         Result = SendMessageByNum(Combo1.hWnd, CB_SHOWDROPDOWN, False,
0)
      End If

In the Form1_Load event add some bogus entries using Combo1.AddItem and
give it
a try.  You said you had the 1000 names in the list, this method
searches the list
rather than going back to the database.

(Who would believe it could be that easy???)

To catch the user using the drop down list add:

Private Sub Combo1_Click()
        Text1 = Combo1
End Sub

Working with this awhile I noticed that some text entries did not drop
the list, so
to cause the search to highight the next item in the list after a
missing entry (one
that couldnt be found) I assumed the list was sorted and used this:

Private Sub Text1_Change()
Const WM_USER = &H400
Const CB_FINDSTRING = (WM_USER + 12)
Const CB_SETCURSEL = (WM_USER + 14)
Const CB_SHOWDROPDOWN = (WM_USER + 15)
Dim StringPos As Long, Result As Long
Dim Temp As String
Dim LastLetter As Integer

      If Text1 = "" Then
                'User emptied textbox so close dropdown
                Result = SendMessageByNum(Combo1.hWnd, CB_SHOWDROPDOWN,
False, 0)
      Else
                StringPos = SendMessageByString&(Combo1.hWnd,
CB_FINDSTRING, 0, Text1)
                'If not found then find next line beyond missing entry
                Temp = LCase$(Text1)
                LastLetter = Len(Temp)
                Do While StringPos < 0 And Right(Temp, 1) <= "z" And
LastLetter > 0
                        If Right(Temp, 1) < "z" Then
                                'Increase last letter by one letter (up
to 'z')
                                Mid(Temp, LastLetter) =
Chr$(Asc(Right(Temp, 1)) + 1)
                                StringPos =
SendMessageByString&(Combo1.hWnd, CB_FINDSTRING, 0, Temp)
                        Else
                                'Tried current length up to z, shorten
string by one letter
                                LastLetter = LastLetter - 1
                                If LastLetter Then Temp = Left(Temp,
LastLetter)
                        End If

                Loop
                If StringPos >= 0 Then
                        If Combo1.ListIndex <> StringPos Then  'avoids
flicker when equal
                                Result = SendMessageByNum(Combo1.hWnd,
CB_SETCURSEL, CInt(StringPos), 0)
                        End If
                        Result = SendMessageByNum(Combo1.hWnd,
CB_SHOWDROPDOWN, True, 0)
                Else
                        'Text was beyond end of list so show last item.
                        Result = SendMessageByNum(Combo1.hWnd, CB_SETCURSEL, Combo1.ListCount
- 1, 0)
                        Result = SendMessageByNum(Combo1.hWnd,
CB_SHOWDROPDOWN, True, 0)
                End If
        End If

End Sub

Quote:

> hello,

> I wonder if anyone can help me with the following.
> I'm trying to write a vb4 interface to provide my quite complex and
> extremely relational access2 database with the necessary data.

> The actual question is if anyone knows how to write a search interface
> that resembles the Help-Find interface in almost all win95 apps; i.e.
> a combination of a textbox and a listbox (see what i mean?).
> The list to be searched contains more than 1000 person/band names.

> In fact I managed to create such a thing, and it works (!),  but it
> works extremely slow.

... cut for brievity ...

- Show quoted text -

Quote:
> Thanks a lot.





Sun, 06 Aug 2000 03:00:00 GMT  
 'Help-Find'-style interface for vb4 programmed database search

Sorry that some lines got wrapped.  You can easily
delete the CR and LFs rather than me reposting.

If you have trouble, just ask....

Thanks  :)



Sun, 06 Aug 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. 'Help-Find'-style interface for vb4 programmed database search

2. VB4 - Error 53 'File not found'

3. VB4 - Error 53 'File not found'

4. How to program a 'Find' facility

5. 'System Database' property not found

6. 'Physical database not found'

7. 'Physical database not found' error message

8. 'Creating' Databases in VB4

9. Help! Program Can't Find system directory

10. Replacing styles doesn't set .Found=True

11. Can't find existing styles?

12. VB5 vs VB4 - example program in help doesn't run

 

 
Powered by phpBB® Forum Software