Solved

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

Posted on 2004-10-13
5
199 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 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