Solved

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

Posted on 2004-10-13
5
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 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