Jump to content

Array() equivalent


Go to solution Solved by Mat,

Recommended Posts

Posted
Hello,
 
I need to make a call to a method that takes as a parameter a variant that should be an array of properties. For the specific function that I need to be executed, there are no needed properties, so I would need to pass an empty array. In VB I would just use the Array() constructor, but in AutoIt what can I use? Is there something equivalent?
 
Thank you
Posted

Hi,

Welcome to the autoit forum :)

In the beta version you can create empty arrays (e.g: $aArray[0]), I don't know if it's what you're looking for.

Br, FireFox.

Posted

Welcome to AutoIt and the forum!

You need the latest Beta version of AutoIt. There you can create an empty array.

Global $aArray[]
ConsoleWrite(UBound($aArray) & @LF)

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Opps, sorry :>

Looks like I need to get my feet wet with the new features.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

It's an array, but not an empty array.

Global $aArray = []
ConsoleWrite(VarGetType($aArray) & @LF)
ConsoleWrite(UBound($aArray, 1) & @LF)

returns 1. Strange.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

Thank you very much for your replies. I installed the Beta version and compiled the script again but unfortunately I am getting COM errors ('interface not registered' for $array[] and 'type mismatch' for $array = []). So, I am guessing there must be some small difference in the implementation of the empty table in autoit?

EDIT: It turns out I was passing another parameter wrong and $array = [] did the job after all! Thank you very much again!

Edited by rdr
Posted

  On 9/10/2013 at 9:01 AM, water said:

It's an array, but not an empty array.

Global $aArray = []
ConsoleWrite(VarGetType($aArray) & @LF)
ConsoleWrite(UBound($aArray, 1) & @LF)
returns 1. Strange.

 

 

It's not strange, it's opposite of that. Consistent with the syntax rules of AutoIt:

#include <Array.au3>

Local $aArray[5] = [1, 2]

_ArrayDisplay($aArray)

♡♡♡

.

eMyvnE

Posted

Seems I'm a bit slow on the uptake (today).

Why does UBound($aArray4) return 1? Shouldn't it be 0?

Global $aArray1[0], $aArray2[1], $aArray3 = [1], $aArray4 = []
ConsoleWrite("UBound($aArray1, 1): " & UBound($aArray1, 1) & @LF)
ConsoleWrite("UBound($aArray2, 1): " & UBound($aArray2, 1) & @LF)
ConsoleWrite("UBound($aArray3, 1): " & UBound($aArray3, 1) & @LF)
ConsoleWrite("UBound($aArray4, 1): " & UBound($aArray4, 1) & @LF)
  Quote

>Running:(3.3.9.19):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:TempTest.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop

UBound($aArray1): 0
UBound($aArray2): 1
UBound($aArray3): 1
UBound($aArray4): 1

 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Because array4 has one element - an empty string, because AutoIt doesn't know for "nothing", it always has to be something.

Array literal implies "something".

You may not see the obvious on that simple example, but for more complex ones (multidimensional arrays literals) it will be clear, only your head might hurt at first. jchd can explain better, he's good with words.

♡♡♡

.

eMyvnE

Posted

  On 9/10/2013 at 12:37 PM, Mat said:

[] = [""]

In current language implementation yes. Tomorrow it may be something else. If you leave AutoIt to fill unspecified elements then AutoIt will always use what's "nothing" to it.

  Quote

So there is no such thing as an empty array literal then?

No. And yes. But no.

♡♡♡

.

eMyvnE

Posted

Now it's clear, thanks.

I still prefer to define 2 or 4-dimensional arrays the "traditional" way ;)

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

I do too.

I also think that the language shuldn't, just because of that, have (unlogical) boundaries that would restrict users from prefering something else.

Lifted boundaries give new possibilites even for us.

♡♡♡

.

eMyvnE

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...