TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
K S Reddi Prasad
NA
28
75.3k
Problem in changing the if block code to Switch case.
Apr 27 2011 6:15 AM
Hi all,
I have some code in multiple 'if' blocks, the same functionality i want to do it in Switch case. I tried but i am getting some Exception Here.
I am Having if code like the Following:
Office.DocumentProperties docProp = (Office.DocumentProperties)
Globals.ThisAddIn.Application.ActiveDocument.CustomDocumentProperties;
if (docProp["ReferenceId"] != null)
{
labelControl = (RibbonLabel)Globals.Ribbons[0].Tabs[0].Groups[0].Items[3];
labelControl.Label = docProp["ReferenceId"].Value.ToString();
}
if (docProp["ReferenceType"] != null)
{
labelControl = (RibbonLabel)Globals.Ribbons[0].Tabs[0].Groups[0].Items[4];
labelControl.Label = docProp["ReferenceType"].Value.ToString();
labelReferenceId = (RibbonLabel)Globals.Ribbons[0].Tabs[0].Groups[0].Items[0];
}
if (docProp["CreatedBy"] != null)
{
labelControl = (RibbonLabel)Globals.Ribbons[0].Tabs[0].Groups[0].Items[5];
labelControl.Label = docProp["CreatedBy"].Value.ToString();
}
for the above code, I did like this:
string[] customProperties = { "ReferenceId", "ReferenceType", "CreatedBy"};
foreach(string customProperty in customProperties)
{
switch (docProp["customProperty"])
{
case "ReferenceId": labelControl = (RibbonLabel)Globals.Ribbons[0].Tabs[0].Groups[0].Items[3];
labelControl.Label = docProp["ReferenceId"].Value.ToString();
break;
case "ReferenceType": labelControl = (RibbonLabel)Globals.Ribbons[0].Tabs[0].Groups[0].Items[4];
labelControl.Label = docProp["ReferenceType"].Value.ToString();
labelReferenceId = (RibbonLabel)Globals.Ribbons[0].Tabs[0].Groups[0].Items[0];
break;
case "CreatedBy": labelControl = (RibbonLabel)Globals.Ribbons[0].Tabs[0].Groups[0].Items[4];
labelControl.Label = docProp["ReferenceType"].Value.ToString();
labelReferenceId = (RibbonLabel)Globals.Ribbons[0].Tabs[0].Groups[0].Items[0];
break;
default:
break;
}
}
Any help will be greatly appreciated.
Thanks,
K.S.Reddi Prasad.
Reply
Answers (
3
)
Checkergame continuing
THBImage in Vb 6.0 to a dot net control