Jump to content

Recommended Posts

Posted (edited)

Hi all,

Sometimes we need to know instantly what our array contains. For this, i have made a little function to print your array in console. You may use this function in MsgBox too.

Here is the code.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0
 Author:         kcvinu

 Script Function: Sometimes we need to see what an array or a list contains.
                  And this script will help you to see the all elements without a loop
                  Example : If you have an array like this = Local $MyArray[4] = ['Red','Green','Blue','Yellow']
                            You need to use the fuction like this = PrintList($MyArray)
                            Result : It will print your Array in Console like this
                            [Red,Green,Blue,Yellow]
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

Func PrintList($List)
    If IsArray($List) Then
        Local $txt = ""
        For $i = 0 to UBound($List) -1
            $txt = $txt & "," & $List[$i]
        Next
        Local $out = StringMid($txt,2)
        Global $Result = "[" & $out & "]"
        ConsoleWrite($Result)
        Return $Result
    Else
        MsgBox(0, "List Error", "Variable is not an array or a list")
    EndIf
EndFunc   ;==>PrintList

 

PrintList.au3

Edited by kcvinu
  Reveal hidden contents

 

Posted (edited)

You are aware of the _ArrayDisplay command in the UDF section of the Help file?

I don't wish to discourage you on your programming journey, but I suggest you read what I wrote >here.

P.S. Nice to see you coming along with your programming though. :thumbsup:

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

UEZ of the german forum has already created such an UDF to display the content of an array in a formated way on the console.

It works pretty well :)

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)
  On 2/26/2015 at 3:27 PM, water said:

UEZ of the german forum has already created such an UDF to display the content of an array in a formated way on the console.

It works pretty well :)

 

It can be found here, too (also a version by gil900): 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

  • Moderators
Posted

Hi,

And you can even get _ArrayDisplay itself to nicely format the data when copied via the dialog buttons if you set the $vUser_Separator parameter to a numeric value:

#include <Array.au3>

Local $aArray[][] = [["Item 0-0", "Item 0-1"], ["Item 1-0", "Item 1-1"]]

_ArrayDisplay($aArray, "Formatted", Default, Default, 10, "Column 1|Column 2")
Run the script, press the either of the "Copy Data" buttons and paste into the SciTE console to see what I mean. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Hi all,

I have read your valubale comments. And I have tested the _ArrayDisplay function. I think my function is different from that. Anyway, thanks to those who supported me. :)

  Reveal hidden contents

 

Posted

I think you should compare your function with the UDF written by UEZ. Both write the content of the array to the console.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Hi 

water, Yes. 
  Reveal hidden contents

 

Posted

I made a not so simple, but fairly elegant function to enumerate any size array which also write the contents to the console.  It is in the spoiler section of this post:

It was just a fun exercise.  I can't think of any application/purpose where I would need an array with more than 3 dimensions (I find 2-dimensions to be adequate most of the time), but I wanted to make the func dynamic enough to support whatever I threw at it.
 

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