Unhandled exception in C# code when reading an hyperlink action setting

  • Thread starter Thread starter joel
  • Start date Start date
J

joel

Hi,

I'm trying to use a hypertext action setting to store hidden
information in a character of a text paragraph -- and I'm getting an
unhandled exception in some computers.

Here's how the string info is stored in a character at the beginning of
of a text paragraph:
1. PowerPoint.TextRange tr =
shape.TextFrame.TextRange.Paragraphs(i,1);
2. tr = tr.InsertBefore("_");
3. tr.ActionSettings
[PowerPoint.PpMouseActivation.ppMouseClick].Action =
PowerPoint.PpActionType.ppActionHyperlink;
4. tr.ActionSettings
[PowerPoint.PpMouseActivation.ppMouseClick].Hyperlink.Address =
"http://"+info+"/";
5. tr.Font.Superscript = Microsoft.Office.Core.MsoTriState.msoTrue;

the info is read from the paragraph as follows:

6. tr = shape.TextFrame.TextRange.Paragraphs(i,1).Characters(1,1);
7. if
(tr.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Action ==
PowerPoint.PpActionType.ppActionHyperlink)
8. info = tr.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick]
..Hyperlink.Address;
9. int l = info.Length;
10. info = info.Substring(7,l-8);

On some computers, the calculation in line 7 of the expression:
tr.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Action
raises an unhandled exception (not caught by try-catch). On other
computers, the code works fine.

Any idea what could be causing the exception?

Thanks,

Joel
 
Hi,

Ok, we found the solution:

you have to read the expression in line #7 in steps

PowerPoint.ActionSettings aset = tr.ActionSettings;
PowerPoint.ActionSetting asetmc =
aset[PowerPoint.PpMouseActivation.ppMouseClick];
if (asetmc.Action == PowerPoint.PpActionType.ppActionHyperlink)

A truly nasty bug...

Joel
 
The solution mentioned below is still not enough. The problem is that
the ActionSettings collection is not indexed in C# so you can't
directly refer to its index []. You need to use its enumerator to loop
over the values, -- in practice using the foreach statement.

Joel said:
Hi,

Ok, we found the solution:

you have to read the expression in line #7 in steps

PowerPoint.ActionSettings aset = tr.ActionSettings;
PowerPoint.ActionSetting asetmc =
aset[PowerPoint.PpMouseActivation.ppMouseClick];
if (asetmc.Action == PowerPoint.PpActionType.ppActionHyperlink)

A truly nasty bug...

Joel
Hi,

I'm trying to use a hypertext action setting to store hidden
information in a character of a text paragraph -- and I'm getting an
unhandled exception in some computers.

Here's how the string info is stored in a character at the beginning of
of a text paragraph:
1. PowerPoint.TextRange tr =
shape.TextFrame.TextRange.Paragraphs(i,1);
2. tr = tr.InsertBefore("_");
3. tr.ActionSettings
[PowerPoint.PpMouseActivation.ppMouseClick].Action =
PowerPoint.PpActionType.ppActionHyperlink;
4. tr.ActionSettings
[PowerPoint.PpMouseActivation.ppMouseClick].Hyperlink.Address =
"http://"+info+"/";
5. tr.Font.Superscript = Microsoft.Office.Core.MsoTriState.msoTrue;

the info is read from the paragraph as follows:

6. tr = shape.TextFrame.TextRange.Paragraphs(i,1).Characters(1,1);
7. if
(tr.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Action ==
PowerPoint.PpActionType.ppActionHyperlink)
8. info = tr.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick]
.Hyperlink.Address;
9. int l = info.Length;
10. info = info.Substring(7,l-8);

On some computers, the calculation in line 7 of the expression:
tr.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Action
raises an unhandled exception (not caught by try-catch). On other
computers, the code works fine.

Any idea what could be causing the exception?

Thanks,

Joel
 
Back
Top