Why doesn't this function work? 
Author Message
 Why doesn't this function work?

What this does is get an array of all the items in a listbox.

Function List(Object As Listbox) As String
  Dim s(0) As string
  Dim i,n As Integer
  n=Object.ListCount
  i=0
  For i=0 to n
    Object.ListIndex=i
    s.Append Object.Text
  Next
  Return s //this gives me a type mismatch
End Function

I'm not sure why...I'm supposed to return a string, and s is a string. Any
suggestions?



Tue, 07 Dec 2004 07:05:19 GMT  
 Why doesn't this function work?

Quote:
>  Return s //this gives me a type mismatch

That's because s is an array, but it's expecting a STRING, not an array, as the
return value.

If you did something like return s(3), it would work. Each element in s (eg,
s(0), s(1), and so on) is a string, but s is an array of strings, not a string.

--
"Quand la morale triomphe, il se passe des choses tres vilaines."
Literature. Art. Photography. Forums. Shareware. Kink. Sex.
All at: http://www.xeromag.com/franklin.html



Tue, 07 Dec 2004 07:20:52 GMT  
 Why doesn't this function work?

Quote:

> >  Return s //this gives me a type mismatch

> That's because s is an array, but it's expecting a STRING, not an array,
> as the return value.

I would suggest to make a class holding the array.

Mfg
Christian

--
PLZ Suche
Das neue Postleitzahlensuchprogramm

Vertrieb ber Arktis (www.arktis.de)



Tue, 07 Dec 2004 07:41:07 GMT  
 Why doesn't this function work?

Quote:

> What this does is get an array of all the items in a listbox.

> Function List(Object As Listbox) As String
>   Dim s(0) As string
>   Dim i,n As Integer
>   n=Object.ListCount
>   i=0
>   For i=0 to n
>     Object.ListIndex=i
>     s.Append Object.Text
>   Next
>   Return s //this gives me a type mismatch
> End Function

also you want to change dim s(0) to dim s(-1) otherwise you'll have the
first you append it'll addit at index 1, the 2nd at index 2 and the
correspondence will be off by one.


Tue, 07 Dec 2004 09:42:08 GMT  
 Why doesn't this function work?


Quote:
> Function List(Object As Listbox) As String
> Dim s(0) As string
> Dim i,n As Integer
> n=Object.ListCount
> i=0
> For i=0 to n
>   Object.ListIndex=i
>   s.Append Object.Text
> Next
> Return s //this gives me a type mismatch
> End Function

You could do this is you are requiring a string back

Function List(Object As Listbox) As String
  Dim s As string
  Dim i,n As Integer
  n=Object.ListCount
  i=0

  Object.ListIndex=i
  s =  Object.text

  For i=1 to n
    Object.ListIndex=i
    s =  s + chr(9) + Object.text
  Next
  Return s
End Function

Now you will have a string that has all of the elements with a tab
separating them.  You can use NthField to extract the specific element from
the list.

element = NthField(myString,chr(9),2)

Element will now contain the second element in the ListBox.

I am not sure why you would want this type of function, but here is one
possible solution.

Steve



Tue, 07 Dec 2004 20:53:41 GMT  
 Why doesn't this function work?
Jon Buckley wrote :

Quote:
> What this does is get an array of all the items in a listbox.

> Function List(Object As Listbox) As String
>   Dim s(0) As string
>   Dim i,n As Integer
>   n=Object.ListCount
>   i=0
>   For i=0 to n
>     Object.ListIndex=i
>     s.Append Object.Text
>   Next
>   Return s //this gives me a type mismatch
> End Function

> I'm not sure why...I'm supposed to return a string, and s is a string. Any
> suggestions?

Another suggestion, "For i=0 to n-1" since you starts at 0; Else, you'll have
an outOfBoundsExcepetion when trying to access the last item.


Wed, 08 Dec 2004 05:26:50 GMT  
 Why doesn't this function work?

Quote:
> Jon Buckley wrote :

>> What this does is get an array of all the items in a listbox.

>> Function List(Object As Listbox) As String
>> Dim s(0) As string
>> Dim i,n As Integer
>> n=Object.ListCount
>> i=0
>> For i=0 to n
>> Object.ListIndex=i
>> s.Append Object.Text
>> Next
>> Return s //this gives me a type mismatch
>> End Function

>> I'm not sure why...I'm supposed to return a string, and s is a string. Any
>> suggestions?

> Another suggestion, "For i=0 to n-1" since you starts at 0; Else, you'll have
> an outOfBoundsExcepetion when trying to access the last item.

Thank you everyone for your help and suggestions. I decided to go with
copying the data to an array (As Christian suggested), and for arnaud and
Eliezer with helpful suggestions.

Thanks everyone!



Wed, 08 Dec 2004 12:03:03 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. why do my function doesn't work!??

2. Help - why doesn't this conjunction work?

3. Why doesn't this equate work

4. Why doesn't the socket always work ?

5. why doesn't FILE{Prop:label} work?

6. Why doesn't this subclass code work?

7. Why doesn't this code work?

8. Why doesn't this WORK?

9. Why doesn't SELF.RestoreField(MyField) work ?

10. why doesn't this hold() code work?

11. Why doesn't my toolbar work?

12. Why doesn't SELF.RestoreField(MyField) work ?

 

 
Powered by phpBB® Forum Software