Solved

ArrayList does not except arguments passed   Multidimensional Array

Posted on 2007-11-18
13
244 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
[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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

635 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