Add Arraylist to Arraylist

R

rdi

I have 3 classes:

mailBox, mailFilter & mailFilterSet

I then have an arraylist. Each element in the array is of type mailBox (variable name is mbox). One item of the mailbox class is an arraylist named filterSet. The intended purpose is for this arrayList to contain type mailFilterSet elements. The mailFilterSet class contains a string (the name of the filter set) and an arraylist--which is intened to contain mailFilter elements.

'This works fine <= Create the mbox in array position 1.
dim i as integer = 0
mbox.Add(New mailbox())

'Then when I try to create the first element in the filter set array, it fails and gives
'an unhandled exception of type 'system.NullReferenceException".
'Additional variable or With block variable not set.
mbox.(i).filterSet.add(new mailFilterSet)

The class definitions are below.

TIA

Public Class mailbox
Public mbox As String
Public acct As String
Public fromName As String
Public fromAddress As String
Public replyAddress As String
Public ReplyMessage As String
Public ReplyAttach As String
Public sender As String
Public forwardAddress As String
Public forwardMessage As String
Public forwardAttach As String
Public sendReply As Boolean = False
Public sendForward As Boolean = False
Public replyIncludeOriginal As Boolean = True
Public forwardIncludeOriginal As Boolean = True

'0 = As Attachment
'1 = In Brackets
'2 = Unchanged
Public replyIncludeOriginalMethod As Integer = 0

Public forwardIncludeOriginalMethod As Integer = 0
Public filterSet As ArrayList
End Class

Public Class mailFilterSet
Public filterName As String
Public filter As ArrayList
End Class

Public Class mailFilter
'andor:
'2 = n/a
'1 = And
'0 = Or
Public andor As Integer
'field:
'0 = To:
'1 = From:
'2 = Reply:
'3 = Subject
'4 = Message
Public field As Integer
'TYPE:
' 0 => = <= Equal
'1 => != <= Not Equal
'2 => *= <= Ends With
'3 => =* <= Begins With
'4 => *=* <= Contains
'5 => !*=* <= Doesn't Contain
Public type As Integer
Public content As String
End Class
 
A

Armin Zingler

rdi said:
I have 3 classes:

mailBox, mailFilter & mailFilterSet

I then have an arraylist. Each element in the array is of type

In the array or in the arraylist?
mailBox (variable name is mbox). One item of the mailbox class is an
arraylist named filterSet. The intended purpose is for this
arrayList to contain type mailFilterSet elements. The mailFilterSet
class contains a string (the name of the filter set) and an
arraylist--which is intened to contain mailFilter elements.

'This works fine <= Create the mbox in array position 1.
dim i as integer = 0
mbox.Add(New mailbox())

'Then when I try to create the first element in the filter set array,
it fails and gives 'an unhandled exception of type
'system.NullReferenceException". 'Additional variable or With block
variable not set.
mbox.(i).filterSet.add(new mailFilterSet)
^
Is here really a dot?

First, I'd split the line to find the error (maybe wrong types name but you
see the point):

dim mb as mailbox
dim fs as mailfilter
dim mfs as mailfilterset

mb = mbox(i)
fs = mb.filterset
mfs = new mailfilterset
fs.add(mfs)


I guess, you only declared mbox, but didn't assign an array (use Redim for
this). Or, the filterset property returns Nothing, which means, that you
didn't create an Arraylist (use the New keyword) in the mailbox class and/or
didn't assign it to the private field returned by the filterset property.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
R

rdi

Armin,

Thanks.

1) When I couldn't find my message last night, I thought it didn't get posted for some reason. So I reposted it.
2) After I posted it again, I kept working. I realized the problem--it was that pesky NEW statement.
3) as far as the typos you found go, the previous post wasn't a TOTAL copy/paste. I tried to clean it up a little to make it easier to read.
The result:

Public Class mailbox
'a buch of string and integer variables

'here's the arraylist I'm concerned with
public filterSet as NEW arraylist '<=I didn't have the NEW before
end class
public class mailFilterSet
public filterName as string

'and this arraylist too
public filter as NEW arraylist '<=I didn't have the NEW before either
end class
public class mailFilter
'a buch of string and integer variables
end class
Public mbox as new arraylist
sub main ()
dim i, j, k as integer
for i = 0 to upperLimit
mbox.add(new mailBox)
'set the other variables
for j = 0 to upperLimit
mbox(i).filterSet.add(new mailFilterSet)
mbox(i).filterSet(j).filterName = filterName
for k = 0 to upperLimit
mbox(i).filterSet(j).filter.add(new mailFilter)
'set all the varialbles in this filter
Next
Next
Next
end sub


mbox(1)
integer variables
string variables
mailFilterSet(1)
filterName
mailFilter(1)
mailFilter(2)
mailFilter(3)
mailFilterSet(2)
filterName
mailFilter(1)
mailFilter(2)
mailFilter(3)
mailFilter(4)
mailFilterSet(2)
filterName
mailFilter(1)
mailFilter(2)
mailFilter(3)
mailFilter(4)
mbox(2)
integer variables
string variables
mailFilterSet(1)
filterName
mailFilter(1)
mailFilter(2)
mailFilter(3)
mailFilterSet(2)
filterName
mailFilter(1)
mailFilter(2)
mailFilter(3)
mailFilter(4)
mailFilterSet(2)
filterName
mailFilter(1)
mailFilter(2)
mailFilter(3)
 

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

Top