• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

VB.Net queue question

Maybe I am burned out, but I am having trouble figuring this out and don't have the time to play with it.  

        Dim Current_Node As New Node
        Dim Fringe As New Queue
        Fringe.Enqueue("EMPTY QUEUE")
        Dim Successors() As Node
        Current_Node.set_node(0, 0, 0, 0, False)
        Fringe.Enqueue(Current_Node)
        Current_Node.set_node(Cannibals, Humans, humans_on_top, Savages_On_Bottom, False)
        MessageBox.Show(Current_Node.string_result)
        Fringe.Enqueue(Current_Node)
        Do
            Current_Node = Fringe.Dequeue()

How come I am getting errors when I try to dequeue?
0
feldmani
Asked:
feldmani
  • 5
  • 4
1 Solution
 
SStoryCommented:
hard to tell. You need to tell us what error you are getting.  If you dequeue one time before the do loop does it give you an error? If so what? If not, it doesn't like being in the loop in whatever way you are using it.

I need more info.
0
 
feldmaniAuthor Commented:
The error happens as soon as I enter the loop.  I step through the problem.  The error I am getting differs, If I enqueue the string first, it says comparing wrong variables.  If not, it says queue is empty.  Why is it not recognizing that I am putting nodes in the queue?
0
 
SStoryCommented:
How could you put in a string first, then dequeue it to a node and expect that to work?
        Fringe.Enqueue("EMPTY QUEUE")

        Current_Node = Fringe.Dequeue()

Current_Node is a Node not a string

I never see where you are creating a new Node each time before enqueing it. If it is an object, you should use New to create one, then enqueue it, then use new to create another, etc.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
feldmaniAuthor Commented:
The problem is  I am comparing things in a queue that are two objects, nodes, and even though they are the same, it won't recognize them.  I believe this has somethign to do with the fact that it is just comparing the reference.  
0
 
SStoryCommented:
I'm not sure I understand. Are you saying you need to do a CTYPE to cast them to node to do the compare?

Current_Node=CTYPE(Fringe.DEQUEUE,Node)
0
 
feldmaniAuthor Commented:
What do you mean?  I might need to do a CTYPE.  It seems to me my problem comes in when I try to cmopare two things that are the same but it says they aren't.  (Hence, it tries to take off the queue twice instead of once.  I am assuming the reason that is happenning is because I am comparing pointers(references) instead of values.
0
 
SStoryCommented:
I think when you use the queue object, it stores objects (of type object).

It is possible that you would need to cast the generic object into an object of type Node before using it as a Node.  That is what CTYPE does, it says take this variable (object) and cast it to a certain type of object.

have you tried the CTYPE statement I sent you?
0
 
feldmaniAuthor Commented:
No, let me give it a try and I will let you know what comes up.  I don't really need the solution anymore per se, since I just used an array list instead (resulting in a huge re-write of code).  But it will be nice to know how to do this for the future.  
0
 
feldmaniAuthor Commented:
SOrry, I made the request before sstory replied.  He helped out, so I would like to give him the credits.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now