ArrayList as a Property type

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

This doesn't work. I guess New is needed someplace but I don't know where?



Public Property Filters() As ArrayList

Get

Filters.Add(cboFilter.Text)

---snip--

Thanks in advance for any info
 
Hi,

Store a local copy of the arraylist to return in the property.



Public Property Filters as ArrayList

Get
Dim marFilters as New Arraylist
marFilters.Add(cboFilter.text)
return marFilters
end get


Ken
-----------------------
This doesn't work. I guess New is needed someplace but I don't know where?



Public Property Filters() As ArrayList

Get

Filters.Add(cboFilter.Text)

---snip--

Thanks in advance for any info
 
August 10, 2004

The property does not maintain an instance of ArrayList itself.
You also have the concept of the property wrong. What you should
do is create a page level variable of ArrayList and then create a
sub that you call to add a filter. Then if you want to retrieve the
filters,
just access the arraylist variable directly. This looks something like:

dim filters as new ArrayList

Private Sub AddFilter()
filters.add(cbofilter.text)
End Sub

Private Sub Button1_Click(....)
if filters(0) = "Something" then
.... ' do something with list
End Sub

A property is maintained by something like this:

dim _userinput as string

Public Property UserInput() as String
Get
return _userinput
End Get
Set (byval value as string)
_userinput = value
End Set
End Property

Then you can use the property like this: Class.Userinput = Something.
I hope this makes sense! Have a good day!


Joseph MCP
 
August 10, 2004

Wouldn't the marFilters go out of scope in your example?
Also, to only have a Get statement, the property declaration
must be marked as ReadOnly. That also looks suspiciously like
a function...

Joseph MCP
 
Can someone confirm this??
The reference variable would go out of scope but the instance would not get
GC since there would still be a reference in the return.
 
Thanks for the reply. It's getting late and I'm not too sharp but I'm having
a problem following your reply.

In a sense I already have a class level variable with the data in it (for
Get); or into which I want to put the data (with Set)
It is a combobox. The property is to get that data or set it.
With that said, do you still think what you wrote applies?

Thanks
 
* " Just Me said:
This doesn't work. I guess New is needed someplace but I don't know where?



Public Property Filters() As ArrayList

Get

Filters.Add(cboFilter.Text)

\\\
Private m_Filters As New ArrayList()

Public Property Filters() As ArrayList
Get
Return m_Filters
End Get
Set(ByVal Value As ArrayList)
m_Filters = Value
End Set
End Property
///
 
August 10, 2004

I sounds like you already were doing the equivilant of what I wrote,
so the answer is no. But now you have me confused of what the problem
is? :-) Maybe I just need to review the posts again. Good job!


Joseph MCP
 
August 10, 2004

By the way, in reviewing the posts, I don't think you have the property
concept wrong. You've got it right. I was more in the mind-set of
functions,
as I didn't see the full code. Good job!


Joseph MCP
 
Thanks for spending so much time

Joseph MCP said:
August 10, 2004

By the way, in reviewing the posts, I don't think you have the property
concept wrong. You've got it right. I was more in the mind-set of
functions,
as I didn't see the full code. Good job!


Joseph MCP
 
Thanks

I remember someone asking what the Return was for.
At the time I thought it was just another way to proceed but I guess it's
more than that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top