Results 1 to 3 of 3

Thread: Listbox Search. API vs. Vb.net Built-in

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    10

    Listbox Search. API vs. Vb.net Built-in

    I have found two ways to search a listbox for a string.

    First way is to use api:
    VB Code:
    1. Option Explicit
    2. Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
    3.  
    4. 'Searchs a listbox for a matching string. Returns the listindex of the matching item.
    5.  
    6. Function ListboxFindString(strSearchString As String, lHwndListbox As Long) As Long
    7.     Const LB_FINDSTRING = &H18F
    8.     ListboxFindString = SendMessage(lHwndListbox , LB_FINDSTRING, -1, ByVal strSearchString)
    9. End Function

    and the second, the vb.net built-in function:
    VB Code:
    1. Dim i As Integer = ListBox1.FindString("String To Find")

    Even tho the second one is much smaller, which one from those is the fastest? Anyone Know?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: Listbox Search. API vs. Vb.net Built-in

    I'm sure that ListBox.FindString is calling the API underneath.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Listbox Search. API vs. Vb.net Built-in

    What do you think the .NET Framework is? It's a layer between you and Windows that calls all the Windows APIs for you to save you having to write ugly, complex code. As a result, .NET code will execute more slowly, but it will generally not be significant enough to notice in the real world. If you're going to start calling API functions in place of .NET properties and methods then you may as well not be using .NET at all. If speed is of the essence then .NET is probably not the platform to be using.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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