Jump to content

Recommended Posts

Posted

Hi there!

I've been converting some code to c# and have run into a few road blocks. First I cannot use WinList as I've grown accustom to in AutoIt.

AutoIt

$aListOfWindows = WinList("[REGEXPTITLE:\ANotepad.*\z]", "")
For $a = 1 to $aListOfWindows[0][0]
    Console.Write($aListOfWindows[$a][0] & @CRLF)
Next

c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static AutoItX3Lib.AutoItX3Class au3;

        static void Main(string[] args)
        {
            au3 = new AutoItX3Lib.AutoItX3Class();
            object aListOfWindows;
            aListOfWindows = au3.WinList("[REGEXPTITLE:\\ANotepad.*\\z]", "");
            for (int a = 1; a < aListOfWindows [0][0]; a++) //Error 18  Cannot apply indexing with [] to an expression of type 'object'

            {
                Console.WriteLine(aListOfWindows[a][0]);
            }
        }
    }
}

Any help would be GREATLY appreciated!

Posted

To be a little more clear:

au3.WinList() returns an object - I have NO idea how the object is structured or how to use it. Can anybody shed some light?

Posted

Ok - I did this.. I dunno if it's the actual fix, but the compiler didn't complain. (I'll test it tomorrow - 1am here)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static AutoItX3Lib.AutoItX3Class au3;

        static void Main(string[] args)
        {
            au3 = new AutoItX3Lib.AutoItX3Class();
            int [][] aListOfWindows;
            aListOfWindows = au3.WinList("[REGEXPTITLE:\\ANotepad.*\\z]", "");
            for (int a = 1; a < aListOfWindows [0][0]; a++) //Error 18  Cannot apply indexing with [] to an expression of type 'object'

            {
                Console.WriteLine(aListOfWindows[0][a]);  
            }
        }
    }
}

Now from the example in the help file it looks like the array is switched - in autoit, $array[$a][0] is the title and $array[$a][1] is the handle... in c# is it the same or is it array[0][a] for the title and array[1][a] for the handle? A little confused. I guess I'll find out when I test it tomorrow.

Funny that the tool tip for the function WinList says it returns an object - but doesn't complain when I set the return value to int [][]....

Posted

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;



namespace Test

{

    class Program

    {

        static AutoItX3Lib.AutoItX3Class au3;



        static void Main(string[] args)

        {

            au3 = new AutoItX3Lib.AutoItX3Class();

            Object [,] aListOfWindows;

            // aListOfWindows = au3.WinList("[REGEXPTITLE:\\ANotepad.*\\z]", "");



            aListOfWindows = (Object[,])au3.WinList("[CLASS:Notepad]", "");



            for (int a = 1; a <= (int)aListOfWindows[0, 0]; a++)

            {

                Console.WriteLine(aListOfWindows[0, a] + ", " + aListOfWindows[1, a]);

            }



            //foreach (object item in aListOfWindows)

            //{

            //    Console.WriteLine(item);

            //}

        }

    }

}

Posted

In fact, I'll mention that int[][] didn't work - I changed it to string[][] and so far the compiler didn't complain. But it's a huge conversion and I haven't been able to test it yet.

Posted

There is a different between multi-dimensional arrays and jagged arrays. The [][] syntax is for jagged array (array of arrays). I don't know if it's correct or possible to reference the return value as a jagged array but for multi-dimensional arrays it works.

Posted (edited)

I write in so many different languages it's hard to keep it all straight. Thank you for pointing this out. (using [][] didn't work as you predicted)

Your example helped me make 342 changes to my script - and now the winlist functions all work.

Edited by c0desmyth

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...