Adding a objet to a queue

G

Guest

I am trying to create a queue of objects. I have a taskHolder object using a
Task class. I have an activeproject object of project class. Each project has
a queue called Tasks.
Everything looks good up to the point that i try to add the taskholder
object to the queue. I get an nullreferenceexception, indicating that
Me.taskholder is not defined. I even added a NULL test and I get a "wooo!"
every time. Even in the debugger I can see the values in taskholder while it
is saying it does not exist.
What am I doing wrong here?

Private Sub WereDone()
'we are done with this form and will now begin the output process
Dim row As Integer

taskHolder.Reset()
row = (Me.ActiveTask.Index - 2)
For count As Integer = 0 To row Step 1
taskHolder.Index = Me.TasksDataGridView1.Item(0, count).Value
taskHolder.Name = Me.TasksDataGridView1.Item(1, count).Value
taskHolder.TaskDuration = Me.TasksDataGridView1.Item(2,
count).Value
taskHolder.Pred.Add(1, (Me.TasksDataGridView1.Item(3,
count).Value))
taskHolder.BM = Me.TasksDataGridView1.Item(4, count).Value
taskHolder.TW = Me.TasksDataGridView1.Item(5, count).Value
If taskHolder Is Nothing Then
MsgBox("oh crap!")
Else
MsgBox("wooo!")
End If
StartForm.ActiveProject.Tasks.Enqueue(Me.taskHolder) <---- Here!
taskHolder.Reset()
Next
MsgBox(StartForm.ActiveProject.Tasks.Count)

End Sub


Thanks!
 
G

Guest

I just tried doing things the correct way, making tenqueue and tdequeue
methods in the project class and using them instead of accesing the queue
directly.
but I still got the same result. If i hover my mouse over the T, I can see
the data.

Public Sub TEnqeue(ByVal T As Task)
Tasks.Enqueue(T) <----exception!
End Sub
 
R

RB

A said:
I just tried doing things the correct way, making tenqueue and tdequeue
methods in the project class and using them instead of accesing the queue
directly.
but I still got the same result. If i hover my mouse over the T, I can see
the data.

Public Sub TEnqeue(ByVal T As Task)
Tasks.Enqueue(T) <----exception!
End Sub
--SNIP--

Presumably you've checked that your Tasks object has been/is still
instantiated? Sorry to sound dopey, but it's all I can think of!!!

Also, can you confirm that the exception is being thrown at the line

Tasks.Enqueue(T)

and not from a line inside the Enqueue function?

Cheers,

RB.
 
G

Guest

Ok, I found it. In my project class i had:
Public Tasks As Queue
insetad of:
Public Tasks As New Queue

I was thinking the problem was with the object I was trying to put in the
queue instead of the queue itself. Duh.
 

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