You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 [Visual Basic] Faster items adding in ComboBox on Wed Aug 18, 2010 11:32 pm

Top


Contributor
Loading
The following code snippet adds 5000 items into a ComboBox. It does it in 2 ways: with the standard AddItem method that Visual Basic provides, and by using Win32 API.
As you'll see, adding ComboBox items with Win32 API is much faster than doing it with standard VB way...
Code:

Private Sub cmdComboAPI_Click()
    Dim strItemText    As String
    Dim intIndex        As Integer
    Dim dblTimer        As Double
   
    cmbTest.Clear
    dblTimer = Timer
    'Adding items with Win32 API
    For intIndex = 1 To 5000
        strItemText = "item number " & CStr(intIndex)
        SendMessage cmbTest.hWnd, CB_ADDSTRING, 0, ByVal strItemText
    Next
    MsgBox Format(Timer - dblTimer, "0.000") & " seconds"

End Sub

Private Sub cmdComboVB_Click()
    Dim strItemText    As String
    Dim intIndex        As Integer
    Dim dblTimer        As Double
   
    cmbTest.Clear
    dblTimer = Timer
    'Adding items with standard AddItem method.
    For intIndex = 1 To 5000
        strItemText = "item number " & CStr(intIndex)
        cmbTest.AddItem strItemText
    Next
    MsgBox Format(Timer - dblTimer, "0.000") & " seconds"

End Sub

View previous topic View next topic Back to top  Message [Page 1 of 1]

Related topics

Permissions in this forum:
You cannot reply to topics in this forum