Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ArrayList does not except arguments passed   Multidimensional Array

Posted on 2007-11-18
13
Medium Priority
?
247 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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
 
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 2000 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

Technology Partners: 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

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

876 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