Solved

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

Posted on 2004-10-13
5
196 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

21 Experts available now in Live!

Get 1:1 Help Now