ArrayToListbox – Add an array of strings to a ListBox or ComboBox

ArrayToListbox – Add an array of strings to a ListBox or ComboBox

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _    hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _    lParam As Any) As LongPrivate Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" _    (ByVal hwndLock As Long) As LongPrivate Const LB_ADDSTRING = &H180Private Const LB_RESETCONTENT = &H184Private Const CB_ADDSTRING = &H143Private Const CB_RESETCONTENT = &H14B' Add an array of string to a listbox or combo box' using API functions, and optionally clearing it first' This procedure is faster than the one based on AddItem methods,' especially with ComboBox controls, and reduces flickering'' FIRST and LAST indicate which portion of the array' should be considered; they default to the first' and last element, respectivelySub ArrayToListBox(ctrl As Object, arr As Variant, Optional clearIt As Boolean, _    Optional ByVal First As Variant, Optional ByVal Last As Variant)    Dim msgReset As Long    Dim msgAdd As Long    Dim hWnd As Long    Dim index As Long        If TypeOf ctrl Is ListBox Then        msgReset = LB_RESETCONTENT        msgAdd = LB_ADDSTRING    ElseIf TypeOf ctrl Is ComboBox Then        msgReset = CB_RESETCONTENT        msgAdd = CB_ADDSTRING    Else        ' none of the above, exit        Exit Sub    End If        If IsMissing(First) Then First = LBound(arr)    If IsMissing(Last) Then Last = UBound(arr)        ' disable redrawing    hWnd = ctrl.hWnd    LockWindowUpdate hWnd        ' clear control if requested    If clearIt Then        SendMessage hWnd, msgReset, 0, 0    End If        ' add all items in the array    For index = First To Last        SendMessage hWnd, msgAdd, 0, ByVal CStr(arr(index))    Next    ' re-enable redrawing    LockWindowUpdate 0End Sub

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as