Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-13
5
Medium Priority
?
205 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 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