Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2007
    Posts
    2

    Thumbs up Unanswered: object required?!?

    hey guys,

    i've been having trouble passing the name of listbox to a function. you can see the code below:

    Function Sort(ByVal listname As ListBox)
    Dim a As Long
    Dim j As Long
    Dim sTemp As String
    Dim sTemp2 As String
    Dim LbList As Variant

    'lb = listname.Name
    x = listname.Width
    MsgBox x

    'Store the list in an array for sorting
    LbList = listname.List
    MsgBox LbList(2)
    'Bubble sort the array on the first value
    For a = LBound(LbList, 1) To UBound(LbList, 1) - 1
    For j = a + 1 To UBound(LbList, 1)
    If LbList(a, 0) > LbList(j, 0) Then
    'Swap the first value
    sTemp = LbList(a, 0)
    LbList(a, 0) = LbList(j, 0)
    LbList(j, 0) = sTemp

    'Swap the second value
    sTemp2 = LbList(a, 0)
    LbList(a, 1) = LbList(j, 1)
    LbList(j, 1) = sTemp2
    End If
    Next j
    Next a

    'Remove the contents of the listbox
    listname.Clear

    'Repopulate with the sorted list
    listname.List = LbList
    End Function

    Private Sub CommandButton3_Click()
    '===list1 is the name of listbox the i want to pass
    sorted (List1)
    End Sub

  2. #2
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    I assume you are using a UserForm with a listbox, if so, then I think your Function (Sub?) definition should be

    Function Sort(ByVal listname As MSForms.ListBox)

    This fully qualifies the object passed.

    You could use Function Sort(ByVal listname As Object), but this is late binding and you will not get the Auto List Members etc.

    HTH


    MTB

Posting Permissions

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