Results 1 to 4 of 4

Thread: Generic populate listbox function with listbox and array as arguments

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    12
    Location

    Generic populate listbox function with listbox and array as arguments

    I'd like to have a generic function to populate my listbox with public arrays (variants). I've done some googling and done my best but it's not good enough.

    The following iss not working for me (the array doesn't seem to read in):

    Private Function populateListbox(lbArg As MSFORMS.ListBox, ParamArray arrX() As Variant)
        lbArg.Clear 'clear the listbox
        Dim cntR As Integer
        If UBound(arrX) > 0 Then 'lame attempt to ensure argument is passed, but it always will be for me.
            For cntR = 0 To UBound(arrX) - 1
                lbArg.AddItem CStr(arrX(cntR))  'populate the listbox with array contents
            Next cntR
        End If
    End Function
    and the function call as follows:
    Call populateListbox(ListBox1, fnm) ' where fnm is a variant array

    arrX argunet doesn't seem to be read into the function, even though when the array is passed in before entering the function I can see it is indeed a variant array with one element. hovering over cstr(arrx(cntR)) in debug mode shows type mismatch and hoering over arrX shows nothing. Debug.print(arrx(0)) gives a runtime error 13 in debug mode (breakpoints enabled)

    Any help would be most appreciated on this.
    Last edited by Aussiebear; 02-07-2025 at 05:27 PM.

Tags for this Thread

Posting Permissions

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