If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > object required?!?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-08-07, 21:43
dotpao dotpao is offline
Registered User
 
Join Date: Mar 2007
Posts: 2
Thumbs up 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
Reply With Quote
  #2 (permalink)  
Old 03-13-07, 03:59
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On