Solved

ArrayList does not except arguments passed   Multidimensional Array

Posted on 2007-11-18
13
238 Views
Last Modified: 2013-12-17
Original Question
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22968639.html
--------------------------------------------------
I receive 3 errors when I try to use the code provided in the soloution
Error      1      The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?)      C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\SQT.cs      4433      32      SITS-SQT
Error      2      The best overloaded method match for 'System.Collections.ArrayList.Add(object)' has some invalid arguments      C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\SQT.cs      4433      21      SITS-SQT
Error      3      Argument '1': cannot convert from 'Data' to 'object'      C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\SQT.cs      4433      28      SITS-SQT
--------------------------------------------------------------------------------------------------------------------
Segment of Code that generates error
ArrayList al = new ArrayList();
0
Comment
Question by:Trypsim
  • 6
  • 6
13 Comments
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20309576
Hi, put this at the top of your code
using System.Data

Open in new window

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20309583
appears to be you need the following directive at the top of SQT.cs:

using clrtest;
0
 

Author Comment

by:Trypsim
ID: 20309593
using System.Data;  // Included in my libraries

The actual line of code that generates the error is  -->  al.Add(new Data (HName, LstLgn));

I annotated that incorrectly in the question.

Thanks for help though :-D



0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20309612
Data class belongs to the clrtest namespace.
Have you followed my suggestion?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20309615
by the way, Data is not a good name for a class, since there is a Data namespace in .net
Try to change it.
0
 

Author Comment

by:Trypsim
ID: 20309626
I am trying to figure out how to add the clrtest library.  Do I need to add a refrence?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20309649
>>I am trying to figure out how to add the clrtest library.  Do I need to add a refrence?
Not at all.  in the previous question you mentioned, the answer proposed by evilrix was near to the Program class, in the program.cs file.
Just include the .cs file with the Data class inside your code. You don't need any other reference.
Notice the Data class was define inside the 'clrtest' namespace
0
 

Author Comment

by:Trypsim
ID: 20309686
I dont have a clrtest namespace that I have created?  I am a bit confused lets bring the code that was provided into this segment.  I do not see anywhere in the final code segment where clrtest was defined.  I am probably missing something here but please continue to help it is greatly appreciated.
private ArrayList Button_1_Click(object sender, EventArgs e)

{

//////////////////////////////////////////////////////////////////////

        // Create new array

        ArrayList al = new ArrayList();

//////////////////////////////////////////////////////////////////////

 

        string OUDN = txtTargetList_Path.Text;

        try

        {

            DirectoryEntry entry = new DirectoryEntry("LDAP://" + OUDN);

            DirectorySearcher DirSearch = new DirectorySearcher(entry);

            DirSearch.Filter = "(objectClass=computer)";

            DirSearch.PageSize = 100000;

 

            foreach(SearchResult results in DirSearch.FindAll())

            {

                string Line = "";

                string HName = "";

                string LstLgn = "";

                

                foreach(string Value in                                 results.Properties.PropertyNames)

                {

                    if(results.Properties[Value]!=null)

                    {

                        if (Value == "name")

                        {

                            HName = (string)results.Properties[Value][0];

                        }

                        if(Value == "lastlogon")

                        {

                            long lastLogon = (long)results.Properties[Value][0];

                            LstLgn = DateTime.FromFileTime(lastLogon).ToString(); 

                        }

                    }

                }

                Line = HName + "," + LstLgn;

                listBox1.Items.Add(Line);

 

//////////////////////////////////////////////////////////////

                // Add name/logintime to array

                al.Add(new Data(HName, LstLgn));

//////////////////////////////////////////////////////////////

            }

        }

        catch (IOException Iox)

        {

            lstErrorLog.Items.Add(Iox.Data.ToString());

        }

        catch (DirectoryServicesCOMException ex)

        {

            lstErrorLog.Items.Add(ex.Message.ToString());

        }

 

//////////////////////////////////////////////////////////////////////

        // Return array

        return al;

//////////////////////////////////////////////////////////////////////

}

Open in new window

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20309726
How is Data defined?
I assume it is defined exactly like in the previous question, that is, inside a namespace called clrtest.
 
0
 

Author Comment

by:Trypsim
ID: 20309748
Ok I see what you are saying now apparently he provided a class object for clrtest.  I added it as an existing file to my project and used the using clrtest.  I now have another error?
--------------
Error      1      Program 'C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\obj\Debug\SITS-SQT.exe' has more than one entry point defined: 'SITS_SQT.Program.Main()'      C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\Program.cs      13      21      SITS-SQT
Error      2      Program 'C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\obj\Debug\SITS-SQT.exe' has more than one entry point defined: 'clrtest.Program.Main(string[])'      C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\clrtest.cs      51      21      SITS-SQT
-----------
0
 

Author Comment

by:Trypsim
ID: 20309773
The original question was just to show me how to store the results in an array from you query to Active Directory.  2 objects need to be stored The Name of the Computer and the Last Login Date.
---------------------------------------
The code snipet I sent to the original question is posted in this question.  I just want to store the information in the array and pass it to the calling function.
--------------------------------------
I am wrather new to programming in C# and have only picked up things on my own.  Thanks for the help.
private void Button_1_Click(object sender, EventArgs e)

        {

                string OUDN = txtTargetList_Path.Text;

                try

                {

                    DirectoryEntry entry = new DirectoryEntry("LDAP://" + OUDN);

                    DirectorySearcher DirSearch = new DirectorySearcher(entry);

                    DirSearch.Filter = "(objectClass=computer)";

                    DirSearch.PageSize = 100000;
 

                    foreach(SearchResult results in DirSearch.FindAll())

                    {

                        string Line = "";

                        string HName = "";

                        string LstLgn = "";

                        

                        foreach(string Value in results.Properties.PropertyNames)

                        {

                            if(results.Properties[Value]!=null)

                            {

                                if (Value == "name")

                                {

                                    HName = (string)results.Properties[Value][0];

                                }

                                if(Value == "lastlogon")

                                {

                                    long lastLogon = (long)results.Properties[Value][0];

                                    LstLgn = DateTime.FromFileTime(lastLogon).ToString(); 

                                }

                            }

                        }

                        Line = HName + "," + LstLgn;

                        listBox1.Items.Add(Line);

                    }

                }

                catch (IOException Iox)

                {

                    lstErrorLog.Items.Add(Iox.Data.ToString());

                }

                catch (DirectoryServicesCOMException ex)

                {

                    lstErrorLog.Items.Add(ex.Message.ToString());

                }

        }

Open in new window

0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20309795
OK, you application had a Main() method, in Program.cs
In clrtest.cs, you have a Main() method again, just remove it. It was just put by the answerer to give an example.
0
 

Author Closing Comment

by:Trypsim
ID: 31409852
Spent alot of time assisting me with this issue, I really do apprediate the help.  Made my issue alot easier to understand.  Thanks again!!!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

11 Experts available now in Live!

Get 1:1 Help Now