Solved

Syntax Error somewhere in my program, help me find it please!

Posted on 2004-10-13
5
197 Views
Last Modified: 2010-04-15
Here is the code I'm working on (I'm trying to get good at AD programming):

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.DirectoryServices;

namespace CheckOpenPorts
{
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows.Forms.Form
      {
            private System.Windows.Forms.Panel mainPanel;
            private System.Windows.Forms.TreeView ctr_tree;
            private System.Windows.Forms.Splitter splitter1;
            private System.Windows.Forms.ListView ctr_list;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
                  this.mainPanel = new System.Windows.Forms.Panel();
                  this.ctr_tree = new System.Windows.Forms.TreeView();
                  this.splitter1 = new System.Windows.Forms.Splitter();
                  this.ctr_list = new System.Windows.Forms.ListView();
                  this.mainPanel.SuspendLayout();
                  this.SuspendLayout();
                  //
                  // mainPanel
                  //
                  this.mainPanel.Controls.Add(this.ctr_list);
                  this.mainPanel.Controls.Add(this.splitter1);
                  this.mainPanel.Controls.Add(this.ctr_tree);
                  this.mainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
                  this.mainPanel.Location = new System.Drawing.Point(0, 0);
                  this.mainPanel.Name = "mainPanel";
                  this.mainPanel.Size = new System.Drawing.Size(376, 437);
                  this.mainPanel.TabIndex = 0;
                  //
                  // ctr_tree
                  //
                  this.ctr_tree.Dock = System.Windows.Forms.DockStyle.Left;
                  this.ctr_tree.ImageIndex = -1;
                  this.ctr_tree.Location = new System.Drawing.Point(0, 0);
                  this.ctr_tree.Name = "ctr_tree";
                  this.ctr_tree.SelectedImageIndex = -1;
                  this.ctr_tree.Size = new System.Drawing.Size(121, 437);
                  this.ctr_tree.TabIndex = 0;
                  this.ctr_tree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.select);
                  //
                  // splitter1
                  //
                  this.splitter1.Location = new System.Drawing.Point(121, 0);
                  this.splitter1.Name = "splitter1";
                  this.splitter1.Size = new System.Drawing.Size(3, 437);
                  this.splitter1.TabIndex = 1;
                  this.splitter1.TabStop = false;
                  //
                  // ctr_list
                  //
                  this.ctr_list.Dock = System.Windows.Forms.DockStyle.Fill;
                  this.ctr_list.Location = new System.Drawing.Point(124, 0);
                  this.ctr_list.Name = "ctr_list";
                  this.ctr_list.Size = new System.Drawing.Size(252, 437);
                  this.ctr_list.TabIndex = 2;
                  this.ctr_list.View = System.Windows.Forms.View.Details;
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(376, 437);
                  this.Controls.Add(this.mainPanel);
                  this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
                  this.Name = "Form1";
                  this.Text = "Check Open Ports";
                  this.mainPanel.ResumeLayout(false);
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {

                  FrmConnect con = new FrmConnect();

                  if(con.ShowDialog() == DialogResult.OK)
                  {

                        //lets capture our User & Passw:
                        string[] temp=con.returnResults();
               
                        //if User&Pass are submitted launch main
                        Form1 frm = new Form1();
               
                        //Pass User&Passw to Connect method
                        frm.Connect(temp);
                        Application.Run(frm);
                  }
            }
            private void Connect(string[] temp)
            {
                  //Get the strings from Array
                  str=temp;

                  //Pass Connet info to DirextoryEntry object:
                  Base = new DirectoryEntry("LDAP://"+str.GetValue(0).ToString(),
                        str.GetValue(1).ToString(),str.GetValue(2).ToString());
           
                  //Read the root:
                  if(Base != null)
                  {
                        ctr_tree.Nodes.Clear();
                        ctr_tree.BeginUpdate();

                        TreeNode childNode = ctr_tree.Nodes.Add(Base.Name);
                        childNode.Tag = Base;
                               
                        try
                        {
                              foreach(DirectoryEntry rootIter in Base.Children)
                              {
                                    TreeNode RootNode = childNode.Nodes.Add(rootIter.Name);
                                    RootNode.Tag = rootIter;
                              }    
                        }
                        finally
                        {
                              childNode.Expand();
                              ctr_tree.EndUpdate();
                        }
                  }
            }

            private void select(object sender, System.Windows.Forms.TreeViewEventArgs e)
            {
                  private DirectoryEntry Base;
                  private string[] str;

                  //Fill the TreeView dynamic after Click
                  if( e.Node.Nodes.Count == 0 )
                  {
                        DirectoryEntry parent = (DirectoryEntry)e.Node.Tag;
                if(parent != null)
                        {
                    if(parent.Children != null)
                              {
                        foreach(DirectoryEntry Iter in parent.Children)
                                    {
                                          TreeNode childNode = e.Node.Nodes.Add(Iter.Name);
                                          childNode.Tag = Iter;
                                    }
                       
                    }
                }
            }

                  //Fill the ListView Element
                  try
                  {
                        DirectoryEntry list =(DirectoryEntry)e.Node.Tag;
                        if(list!=null)
                        {
                              ctr_list.Clear();
                              //Add some information to ListView ELement
                              ctr_list.Columns.Add("Attribute",90,HorizontalAlignment.Left);
                              ctr_list.Columns.Add("Value",350,HorizontalAlignment.Left);

                              foreach(object listIter in list.Properties.PropertyNames)
                              {
                                    foreach(Object Iter in list.Properties[listIter.ToString()])
                                    {
                                          System.Windows.Forms.ListViewItem item = new System.Windows.Forms.ListViewItem(listIter.ToString(),0);
                                          item.SubItems.Add(Iter.ToString());
                                          ctr_list.Items.AddRange( new ListViewItem[] {item});
                                    }
                              }
                        }
                  }
                  catch(System.Exception ex)
                  {
                        MessageBox.Show(ex.Message);
                  }
      }
}


I keep getting a " } expected" after this line:  

private void select(object sender, System.Windows.Forms.TreeViewEventArgs e)
            {

I've counted all my curly braces and I can't find what's wrong.

Thanks!
0
Comment
Question by:jnewton03
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:praneetha
ID: 12302244
 catch(System.Exception ex)
               {
                    MessageBox.Show(ex.Message);
               }
     }//end of  private void select(object sender, System.Windows.Forms.TreeViewEventArgs e)

}//end of public class Form1 : System.Windows.Forms.Form

you nees one more

} // close namespace CheckOpenPorts

0
 

Author Comment

by:jnewton03
ID: 12302285
Still the same problem even after I added the additional brace:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.DirectoryServices;

namespace CheckOpenPorts
{
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows.Forms.Form
      {
            private System.Windows.Forms.Panel mainPanel;
            private System.Windows.Forms.TreeView ctr_tree;
            private System.Windows.Forms.Splitter splitter1;
            private System.Windows.Forms.ListView ctr_list;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
                  this.mainPanel = new System.Windows.Forms.Panel();
                  this.ctr_tree = new System.Windows.Forms.TreeView();
                  this.splitter1 = new System.Windows.Forms.Splitter();
                  this.ctr_list = new System.Windows.Forms.ListView();
                  this.mainPanel.SuspendLayout();
                  this.SuspendLayout();
                  //
                  // mainPanel
                  //
                  this.mainPanel.Controls.Add(this.ctr_list);
                  this.mainPanel.Controls.Add(this.splitter1);
                  this.mainPanel.Controls.Add(this.ctr_tree);
                  this.mainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
                  this.mainPanel.Location = new System.Drawing.Point(0, 0);
                  this.mainPanel.Name = "mainPanel";
                  this.mainPanel.Size = new System.Drawing.Size(376, 437);
                  this.mainPanel.TabIndex = 0;
                  //
                  // ctr_tree
                  //
                  this.ctr_tree.Dock = System.Windows.Forms.DockStyle.Left;
                  this.ctr_tree.ImageIndex = -1;
                  this.ctr_tree.Location = new System.Drawing.Point(0, 0);
                  this.ctr_tree.Name = "ctr_tree";
                  this.ctr_tree.SelectedImageIndex = -1;
                  this.ctr_tree.Size = new System.Drawing.Size(121, 437);
                  this.ctr_tree.TabIndex = 0;
                  this.ctr_tree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.select);
                  //
                  // splitter1
                  //
                  this.splitter1.Location = new System.Drawing.Point(121, 0);
                  this.splitter1.Name = "splitter1";
                  this.splitter1.Size = new System.Drawing.Size(3, 437);
                  this.splitter1.TabIndex = 1;
                  this.splitter1.TabStop = false;
                  //
                  // ctr_list
                  //
                  this.ctr_list.Dock = System.Windows.Forms.DockStyle.Fill;
                  this.ctr_list.Location = new System.Drawing.Point(124, 0);
                  this.ctr_list.Name = "ctr_list";
                  this.ctr_list.Size = new System.Drawing.Size(252, 437);
                  this.ctr_list.TabIndex = 2;
                  this.ctr_list.View = System.Windows.Forms.View.Details;
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(376, 437);
                  this.Controls.Add(this.mainPanel);
                  this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
                  this.Name = "Form1";
                  this.Text = "Check Open Ports";
                  this.mainPanel.ResumeLayout(false);
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {

                  FrmConnect con = new FrmConnect();

                  if(con.ShowDialog() == DialogResult.OK)
                  {

                        //lets capture our User & Passw:
                        string[] temp=con.returnResults();
               
                        //if User&Pass are submitted launch main
                        Form1 frm = new Form1();
               
                        //Pass User&Passw to Connect method
                        frm.Connect(temp);
                        Application.Run(frm);
                  }
            }
            private void Connect(string[] temp)
            {
                  //Get the strings from Array
                  str=temp;

                  //Pass Connet info to DirextoryEntry object:
                  Base = new DirectoryEntry("LDAP://"+str.GetValue(0).ToString(),
                        str.GetValue(1).ToString(),str.GetValue(2).ToString());
           
                  //Read the root:
                  if(Base != null)
                  {
                        ctr_tree.Nodes.Clear();
                        ctr_tree.BeginUpdate();

                        TreeNode childNode = ctr_tree.Nodes.Add(Base.Name);
                        childNode.Tag = Base;
                               
                        try
                        {
                              foreach(DirectoryEntry rootIter in Base.Children)
                              {
                                    TreeNode RootNode = childNode.Nodes.Add(rootIter.Name);
                                    RootNode.Tag = rootIter;
                              }    
                        }
                        finally
                        {
                              childNode.Expand();
                              ctr_tree.EndUpdate();
                        }
                  }
            }

            private void select(object sender, System.Windows.Forms.TreeViewEventArgs e)
            {
                  private DirectoryEntry Base;
                  private string[] str;

                  //Fill the TreeView dynamic after Click
                  if( e.Node.Nodes.Count == 0 )
                  {
                        DirectoryEntry parent = (DirectoryEntry)e.Node.Tag;
                if(parent != null)
                        {
                    if(parent.Children != null)
                              {
                        foreach(DirectoryEntry Iter in parent.Children)
                                    {
                                          TreeNode childNode = e.Node.Nodes.Add(Iter.Name);
                                          childNode.Tag = Iter;
                                    }
                       
                    }
                }
            }

                  //Fill the ListView Element
                  try
                  {
                        DirectoryEntry list =(DirectoryEntry)e.Node.Tag;
                        if(list!=null)
                        {
                              ctr_list.Clear();
                              //Add some information to ListView ELement
                              ctr_list.Columns.Add("Attribute",90,HorizontalAlignment.Left);
                              ctr_list.Columns.Add("Value",350,HorizontalAlignment.Left);

                              foreach(object listIter in list.Properties.PropertyNames)
                              {
                                    foreach(Object Iter in list.Properties[listIter.ToString()])
                                    {
                                          System.Windows.Forms.ListViewItem item = new System.Windows.Forms.ListViewItem(listIter.ToString(),0);
                                          item.SubItems.Add(Iter.ToString());
                                          ctr_list.Items.AddRange( new ListViewItem[] {item});
                                    }
                              }
                        }
                  }
                  catch(System.Exception ex)
                  {
                        MessageBox.Show(ex.Message);
                  }
            }
      }
}
0
 
LVL 15

Accepted Solution

by:
praneetha earned 250 total points
ID: 12302343
oh

  private void select(object sender, System.Windows.Forms.TreeViewEventArgs e)
          {
               private DirectoryEntry Base;
               private string[] str;


you can't have private inside a methos..remove the private
0
 

Author Comment

by:jnewton03
ID: 12302390
Of course!  I can't believe I missed that!  Thanks!
0
 
LVL 15

Expert Comment

by:praneetha
ID: 12302468
u r welcome
have a good day.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now