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