MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Function variable


Posted by Ben on September 17, 2000 9:23 AM

I can't figure this one out. This function returns an error when called with "If isinbox("Name", Listbox1)..." because ListBox1 returns it's selected string:

Function isinbox(mystring As String, lb As ListBox) As Boolean
Dim i As Integer
For i = 0 To lb.ListCount - 1
If UCase(mystring) = UCase(lb.List(i)) Then
isinbox = True
Exit Function
Else: isinbox = False
End If
Next i
End Function

It works fine w/o ListBox variable:

Function isinbox(mystring As String) As Boolean
Dim i As Integer
For i = 0 To ListBox1.ListCount - 1
If UCase(mystring) = UCase(ListBox1.List(i)) Then
isinbox = True
Exit Function
Else: isinbox = False
End If
Next i
End Function

...except that it requires a function for each listbox. How do I resolve the type mismatch?


Posted by Ivan Moala on September 17, 0100 9:28 PM

Ben
I thought you resolved this??
Try;
declaring Lb as a variant or an Object.
eg.Function isinbox(mystring As String, lb) As Boolean
OR
Function isinbox(mystring As String, lb as Object) As Boolean

Then call as;

Result = isinbox(string,ListBox1)


HTH

Ivan


Ivan