Warning

 

Close

Confirm Action

Are you sure you wish to do this?

Confirm Cancel
BCM
User Panel

Site Notices
Posted: 1/13/2006 3:24:40 PM EDT
Ok, I'm working on putting together this Visio add-in to pull info from Active Directory.  Basically...I'm just following the directions laid out in this article Generating Active Directory Diagrams with Visio 2003 and Visual Studio .NET 2003

Disclaimer: my f00 is very week...I'm not a programmer.. so any help would be greatly appreciated.  If you need any more info just let me know.

I'm nearly complete but I am having some trouble building the project due to a build error:

"C:\path\to\project\Connect.cs(103): ; expected"

Heres the code: (check the over sized bold part, thats where the error is supposed to be)


private void CreateButton()
{
try
{
CommandBars cmdBars = (CommandBars)vsoApplication.CommandBars;
CommandBar cmdBar = null;
try
{
cmdBar = cmdBars.Add(
"UserDiagram", MsoBarPosition.msoBarTop,
Missing.Value, true);

CommandBarButton button = (CommandBarButton)cmdBar.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, Missing.Value, true);

button.Caption = "Create Users Diagram";
button.Style = MsoButtonStyle.msoButtonCaption;
button.Click += new_CommandBarButtonEvents_ClickEventHandler button_Click;
        cmdBar.Visible = true;
}
catch
{
cmdBar = cmdBars["UserDiagram"];
}
}
catch(Exception ex)
{
MessageBox.Show(
"Error while creating the toolbar:" + ex.ToString());
}
}

private void button_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
using(ConnectionDialog dialog = new ConnectionDialog())
{
if (dialog.ShowDialog() == DialogResult.OK)
{
DiagramGenerator dg = new DiagramGenerator(vsoApplication);
dg.CreateDiagram(dialog.DepartmentName, dialog.Users);
}
}
}

Link Posted: 1/13/2006 3:26:08 PM EDT
[#1]
I'm not a C# programmer, but +=?
Link Posted: 1/13/2006 3:29:01 PM EDT
[#2]
Not sure what that is... its not being reported as an error and if I remove it the error in question above is still listed....

Programming makes my brain hurt.  I wouldnt be doing this if MS would have left this functionality in Visio.. they dropped it after 2002
Link Posted: 1/13/2006 3:31:25 PM EDT
[#3]
Hmmm...I have both Visio 2003 and VS.NET 2003. Maybe I'll try it out myself, unless someone else comes up with a solution quicker.
Link Posted: 1/13/2006 3:32:27 PM EDT
[#4]

Quoted:
I'm not a C# programmer, but +=?



Yeah, that seems odd to append a value to / from what seems to be an event handler.

Sure it's not just "="?
Link Posted: 1/13/2006 3:33:52 PM EDT
[#5]
who knows..

try this

button.Click += new CommandBarButtonEvents_ClickEventHandler button_Click;



Link Posted: 1/13/2006 3:34:30 PM EDT
[#6]

Quoted:
I'm not a C# programmer, but +=?



i'm not a sharp guy either (wait, that didn't sound right), but it's legal in some languages.

maybe even legit in C, but i'd never use it.

kinda like the "if, else" re written with question colon.

eta: you could always overload it and make it subtract .
Link Posted: 1/13/2006 3:35:34 PM EDT
[#7]
Hell, I'll try it out. I don't have access to AD at the moment, but the damn thing should at least compile.
Link Posted: 1/13/2006 3:35:42 PM EDT
[#8]

Quoted:
I'm not a C# programmer, but +=?



means same as:

button.Click = button.Click + new_CommandBarButtonEvents_ClickEventHandler button_Click;
Link Posted: 1/13/2006 3:38:06 PM EDT
[#9]

Quoted:

Quoted:
I'm not a C# programmer, but +=?



Yeah, that seems odd to append a value to / from what seems to be an event handler.

Sure it's not just "="?



Ok, I just gave it another shot and it didnt work.  The original code in the MS article looks like this:


private void CreateButton() {
  try {
     CommandBars cmdBars = (CommandBars)vsoApplication.CommandBars;
     CommandBar cmdBar = null;
     try {
        cmdBar = cmdBars.Add(
                 "UserDiagram", MsoBarPosition.msoBarTop,
                 Missing.Value, true);

        // Transform the next three lines of code to a single line of code.
        CommandBarButton button = (CommandBarButton)cmdBar.Controls.Add(
        MsoControlType.msoControlButton, Missing.Value, Missing.Value
           Missing.Value, true);

        button.Caption = "Create Users Diagram";
        button.Style = MsoButtonStyle.msoButtonCaption;
     
        // Transform the next three lines of code to a single line of code.
        button.Click += new    
        _CommandBarButtonEvents_ClickEventHandler(button_Click);
       
        cmdBar.Visible = true;
     }
     catch {
        cmdBar = cmdBars["UserDiagram"];
     }
  }
  catch(Exception ex) {
     MessageBox.Show(
        "Error while creating the toolbar:" + ex.ToString());
  }
}



So, I put the parenthesis back around the button_Click and changed += to =, saved, and built and it failed with the following error:

C:\path\to\project\Connect.cs(103): The event 'Microsoft.Office.Core._CommandBarButtonEvents_Event.Click' can only appear on the left hand side of += or -=

So, when I make the code look like its supposed to right from the article it looks like this:


private void CreateButton()
{
try
{
CommandBars cmdBars = (CommandBars)vsoApplication.CommandBars;
CommandBar cmdBar = null;
try
{
cmdBar = cmdBars.Add(
"UserDiagram", MsoBarPosition.msoBarTop,
Missing.Value, true);

CommandBarButton button = (CommandBarButton)cmdBar.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, Missing.Value, true);

button.Caption = "Create Users Diagram";
button.Style = MsoButtonStyle.msoButtonCaption;
button.Click += new_CommandBarButtonEvents_ClickEventHandler (button_Click);
        cmdBar.Visible = true;
}
catch
{
cmdBar = cmdBars["UserDiagram"];
}
}
catch(Exception ex)
{
MessageBox.Show(
"Error while creating the toolbar:" + ex.ToString());
}
}

private void button_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
using(ConnectionDialog dialog = new ConnectionDialog())
{
if (dialog.ShowDialog() == DialogResult.OK)
{
DiagramGenerator dg = new DiagramGenerator(vsoApplication);
dg.CreateDiagram(dialog.DepartmentName, dialog.Users);
}
}
}



But, I get the following error:

C:\path\to\project\Connect.cs(103): Method 'VisioUserDiagrams.Connect.button_Click(Microsoft.Office.Core.CommandBarButton, ref bool)' referenced without parentheses

That caused me to take the parentheses out which then led me to the error that I stated in the initial post.
Link Posted: 1/13/2006 3:42:40 PM EDT
[#10]
replace the line with something like

system("format c:");


eta: don't do it - just kidding.
Link Posted: 1/13/2006 3:44:17 PM EDT
[#11]

Quoted:
replace the line with something like

system("format c:");


eta: don't do it - just kidding.



Maybe later....however... throwing the box out the damn window would be more fun.
Link Posted: 1/13/2006 3:47:19 PM EDT
[#12]

Quoted:

Quoted:
replace the line with something like

system("format c:");


eta: don't do it - just kidding.



Maybe later....however... throwing the box out the damn window would be more fun.



ahhhh, so that's why they call it "windows"
Link Posted: 1/13/2006 3:56:37 PM EDT
[#13]
Every c# line is required to be terminated with an ";" character

So you would write "a = b + c;", not "a +b = c"

That's old school Pascal notation, and speeds up compilation greatly because the compiler isn't looking for line wraps.

The += is a concatenation shorthand.

string a;

a = "The rain in Spain";

a  += " falls mainly on the plains.";

would result in string a =  "The rain in Spain falls mainly on the plains."

Also, in c/c++/c# comparative logic a= b means that a IS b not that a is equivalent to b. a == b means that a has the same definition as b, or that a is equivalent to b.


Link Posted: 1/13/2006 3:57:08 PM EDT
[#14]

Quoted:

Quoted:

Quoted:
I'm not a C# programmer, but +=?



Yeah, that seems odd to append a value to / from what seems to be an event handler.

Sure it's not just "="?



Ok, I just gave it another shot and it didnt work.  The original code in the MS article looks like this:


private void CreateButton() {
  try {
     CommandBars cmdBars = (CommandBars)vsoApplication.CommandBars;
     CommandBar cmdBar = null;
     try {
        cmdBar = cmdBars.Add(
                 "UserDiagram", MsoBarPosition.msoBarTop,
                 Missing.Value, true);

        // Transform the next three lines of code to a single line of code.
        CommandBarButton button = (CommandBarButton)cmdBar.Controls.Add(
        MsoControlType.msoControlButton, Missing.Value, Missing.Value
           Missing.Value, true);

        button.Caption = "Create Users Diagram";
        button.Style = MsoButtonStyle.msoButtonCaption;
     
        // Transform the next three lines of code to a single line of code.
        button.Click += new    
        _CommandBarButtonEvents_ClickEventHandler(button_Click);
       
        cmdBar.Visible = true;
     }
     catch {
        cmdBar = cmdBars["UserDiagram"];
     }
  }
  catch(Exception ex) {
     MessageBox.Show(
        "Error while creating the toolbar:" + ex.ToString());
  }
}



So, I put the parenthesis back around the button_Click and changed += to =, saved, and built and it failed with the following error:

C:\path\to\project\Connect.cs(103): The event 'Microsoft.Office.Core._CommandBarButtonEvents_Event.Click' can only appear on the left hand side of += or -=

So, when I make the code look like its supposed to right from the article it looks like this:


private void CreateButton()
{
try
{
CommandBars cmdBars = (CommandBars)vsoApplication.CommandBars;
CommandBar cmdBar = null;
try
{
cmdBar = cmdBars.Add(
"UserDiagram", MsoBarPosition.msoBarTop,
Missing.Value, true);

CommandBarButton button = (CommandBarButton)cmdBar.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, Missing.Value, true);

button.Caption = "Create Users Diagram";
button.Style = MsoButtonStyle.msoButtonCaption;
button.Click += new_CommandBarButtonEvents_ClickEventHandler (button_Click);
        cmdBar.Visible = true;
}
catch
{
cmdBar = cmdBars["UserDiagram"];
}
}
catch(Exception ex)
{
MessageBox.Show(
"Error while creating the toolbar:" + ex.ToString());
}
}

private void button_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
using(ConnectionDialog dialog = new ConnectionDialog())
{
if (dialog.ShowDialog() == DialogResult.OK)
{
DiagramGenerator dg = new DiagramGenerator(vsoApplication);
dg.CreateDiagram(dialog.DepartmentName, dialog.Users);
}
}
}



But, I get the following error:

C:\path\to\project\Connect.cs(103): Method 'VisioUserDiagrams.Connect.button_Click(Microsoft.Office.Core.CommandBarButton, ref bool)' referenced without parentheses

That caused me to take the parentheses out which then led me to the error that I stated in the initial post.




button.Click += new    
        _CommandBarButtonEvents_ClickEventHandler(button_Click);


the '_' is not continuation. it actually starts with _. so exactly as above more more.....


button.Click += new   _CommandBarButtonEvents_ClickEventHandler(button_Click);
Link Posted: 1/13/2006 4:05:14 PM EDT
[#15]
Sweet, I changed that line to read:


button.Click += new _CommandBarButtonEvents_ClickEventHandler (button_Click);


and.... Rebuild All: 1 succeeded, 0 failed, 0 skipped

Thanks st0newall!!
Link Posted: 1/13/2006 4:16:28 PM EDT
[#16]

This thread is really hard to masturbate to....  
Link Posted: 1/13/2006 4:26:03 PM EDT
[#17]

Quoted:
This thread is really hard to masturbate to....  



I am a pr0grammerz. I halfs no g1rlie5 so I's humps da dishwasher!
Close Join Our Mail List to Stay Up To Date! Win a FREE Membership!

Sign up for the ARFCOM weekly newsletter and be entered to win a free ARFCOM membership. One new winner* is announced every week!

You will receive an email every Friday morning featuring the latest chatter from the hottest topics, breaking news surrounding legislation, as well as exclusive deals only available to ARFCOM email subscribers.


By signing up you agree to our User Agreement. *Must have a registered ARFCOM account to win.
Top Top