Instruction pointer not going pass the other line

W

weird0

i am trying to add nodes to a node dynamically ... and assign its
proerties to a node objects stored inside the array.... when the
ShapeAdded event is fired... ...inside the if block... instruction
pointer does not go pass the other line...

Can anyone tell me what is the reason? and how to solve this
problem ?
here is the code:

private void shapeAddedToPageEventHandler(
Microsoft.Office.Interop.Visio.Shape addedShape) {


Master vsoMaster = addedShape.Master;

//Check whether the shape has a master. If not,
//the shape was created locally.
if (vsoMaster != null)
{
//Check whether the master is "Ellipse".
if (vsoMaster.Name == "Ellipse")
{
nodeArray = new Node[NodeLimit]; // instruction pointer
does not go pass the first line
nodeArray[NodeCount].Name = "Node" +
NodeCount.ToString();
nodeArray[NodeCount].Id = NodeCount.ToString();
addedShape.Name=(string)"Node" +
NodeCount.ToString(); // Ellipse01
addedShape.Text = (string)"Node" +
NodeCount.ToString();

MessageBox.Show(addedShape.Name.ToString());
NodeCount++;
}

Need help
Regards
 
N

Nicholas Paldino [.NET/C# MVP]

Are you doing this in an event handler for a windows forms control? If
so, I suspect that an exception is being thrown somewhere and it is being
swallowed by the control firing the event.
 
P

Peter Duniho

i am trying to add nodes to a node dynamically ... and assign its
proerties to a node objects stored inside the array.... when the
ShapeAdded event is fired... ...inside the if block... instruction
pointer does not go pass the other line...

Can anyone tell me what is the reason? and how to solve this
problem ?

No, no one can. You haven't provided nearly a complete enough example,
and based on the code you did post it seems likely that this is more a
question about using interop with Visio than it is a C#/.NET question.
You'll have better luck posting your question in a newsgroup specific
to the automation of Visio.

That said, most likely some sort of exception is happening on that
line. You didn't even post enough code to show what type "Node" is,
but if it's a value type, it's possible there's something in the
default constructor for the type that is causing an exception. If it's
a reference type, then the rest of the code doesn't make any sense,
because you haven't initialized the array, just allocated it. And of
course, it's always possible NodeLimit is too large and the array
allocation simply fails.

It's possible the problem is one of those things, or something else
completely. There's no way to say for sure given the code you posted.

Pete
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

weird0 said:
i am trying to add nodes to a node dynamically ... and assign its
proerties to a node objects stored inside the array.... when the
ShapeAdded event is fired... ...inside the if block... instruction
pointer does not go pass the other line...

Can anyone tell me what is the reason? and how to solve this
problem ?
here is the code:

private void shapeAddedToPageEventHandler(
Microsoft.Office.Interop.Visio.Shape addedShape) {


Master vsoMaster = addedShape.Master;

//Check whether the shape has a master. If not,
//the shape was created locally.
if (vsoMaster != null)
{
//Check whether the master is "Ellipse".
if (vsoMaster.Name == "Ellipse")
{
nodeArray = new Node[NodeLimit]; // instruction pointer
does not go pass the first line

That is not entirely true. The instruction pointer will go to the next
line, where a NullReferenceException occurs, and the method is exited.

You have created an array of Node references, and each reference in the
array is assigned the default value for a reference, which is null.

You have to create actual Node objects and assign to the array before
you can use them.
nodeArray[NodeCount].Name = "Node" +
NodeCount.ToString();
nodeArray[NodeCount].Id = NodeCount.ToString();
addedShape.Name=(string)"Node" +
NodeCount.ToString(); // Ellipse01
addedShape.Text = (string)"Node" +
NodeCount.ToString();

MessageBox.Show(addedShape.Name.ToString());
NodeCount++;
}

Need help
Regards
 

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