Results 1 to 2 of 2

Thread: Finding the best match

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    1

    Question Finding the best match

    I would like a piece of code that would be activated by a Command Button and would read a number in a Text Box and then compare it with numbers in a List finally to find the best match in the list and copy that into a Label.

    But i dont know how?!

    Please Help

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Finding the best match

    Try something like:

    VB Code:
    1. ' Requred defs...
    2. Private Const LB_FINDSTRING = &H18F
    3. Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
    4.      ByVal hWnd As Long, _
    5.      ByVal wMsg As Long, _
    6.      ByVal wParam As Long, _
    7.      ByRef lParam As Any) As Long
    8.  
    9. Private Function FindLB(Obj As Object, TextToFind As String) As String
    10.     ' Set the value as the index...
    11.     Obj.ListIndex = SendMessage(Obj.hWnd, LB_FINDSTRING, -1, ByVal TextToFind)
    12.     ' Set the functiosn return as the ListIndex value.
    13.     FindCB = Obj.List(Obj.ListIndex)
    14. End Sub

    And then use it like so:

    VB Code:
    1. ' Declare the return variable.
    2. Dim strTheValue As String
    3. ' Set the return value.
    4. ' ListBox1 is the object that represents your listbox.
    5. ' TextBox1 is the object that represents your textbox.
    6. strTheValue = FindLB(ListBox1, TextBox1.Text)
    7. Label1 = strTheValue

    Or, something to that effect

    Cheers,

    RyanJ
    Last edited by sciguyryan; Apr 18th, 2005 at 04:45 PM.
    My Blog.

    Ryan Jones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width