Solved

ArrayList does not except arguments passed   Multidimensional Array

Posted on 2007-11-18
13
240 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Database Connections Not being returned to Connection Pool 7 25
.NET 2008 VB and C# 6 27
Expression Evaluater 3 24
insert value of checklistbox checked 4 25
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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