Jump to content

Assigning a local array with 0 elements


Recommended Posts

It is a standard 0 based array, the value stored at the first element [0] is 0.

it can be manipulated to hold some other value ... $aArray[0] = 55764 ;etc...

I agree, your needs are very confusing.

EDIT:

In the alpha version, you can create an array like so...

Local $aArray[]
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

from post #20 it just looks like you're asking "why can't [0] element be used" when it can?

#include 
Local $aArray[1]  ; Declare array with 1 element
$aArray[0] = "zero element" ; "zero element" exists at element [0]
_ArrayDisplay($aArray) ; Shows array output

So if you wanted [0] and [1] you would declare it as

Local $aArray[2]
instead. It's just counting the elements starting from 0, so the offset will always be -1. Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

It is a standard 0 based array, the value stored at the first element [0] is 0.

it can be manipulated to hold some other value ... $aArray[0] = 55764 ;etc...

No,

local aArray[1] = [0]

Unless I'm reading it wrong, it says to me that this is a 1-based array. not a 0-based array. And I don't understand what the [0] part all by itself means.

I agree, your needs are very confusing.

Why is it confusing to want to be able to assign a value to $aArray[0]? That is a 0-based array, right?

I'm a builder. Mr. Element #1 comes to me to build a house for him. I decide I want to give Mr. Element #1 house address 0. So I build the house ($aArray[0]), and name the house Mr. Element #1's name. ($aArray[0] = "Mr. Element #1").

This is not EXACTLY what my initial post was for, but the essence is the same.

Edited by SlowCoder74
Link to comment
Share on other sites

  • Moderators

SlowCoder74,

Arrays in AutoIt always start with the [0] element. But when you declare an array you pass the total number of elements. So declaring an array like this:

Global $aArray[1] = [9999]

produces a single element array like this:

Element    Value

[0]        9999

That is why UBound will return a value of 1 for this array.

Does that make it clear? ;)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Seems like Melba23 got there before I did.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

So if you wanted [0] and [1] you would declare it as

Local $aArray[2]
instead. It's just counting the elements starting from 0, so the offset will always be -1.

You start counting the elements from 1.

Their index, however, starts at 0.

E.g. the first element has an index of 0.

You can create an array like this:

Local $array[1]

That creates a array with one element (that can be accessed with index 0).

However, sometimes you may want to create an array and assign some initial values in one line, like this:

Local $array[3] = ["how", "are", "you"]

This creates an array with 3 elements and with the elements already filled in: 0: "how", 1: "are", 2: "you"

Edited by Kip
Link to comment
Share on other sites

SlowCoder74,

Arrays in AutoIt always start with the [0] element. But when you declare an array you pass the total number of elements. So declaring an array like this:

Global $aArray[1] = [9999]

produces a single element array like this:

Element Value

[0]     9999

That is why UBound will return a value of 1 for this array.

Does that make it clear? ;)

M23

Yes! That does make it clear. I'll have to adjust my thinking for this difference.
Link to comment
Share on other sites

  • 1 month later...

Wow, that's impressive: I found a 'problem' in AutoIT and it is fixed beforehand, allthough still in alpha-state ;-)

Guys, I wanted to crawl through a tree in a filesystem an do something with special sub-dirs. Those can show up in any position within the tree.

What I did (with LabVIEW) was creating an $array_of_pathes and initializing it by the start path. Than

While Ubound($array_of_pathes) ; is not empty

$ThisPath = _arrayPop($array_of_pathes) ; remove last element

$SubDirs=_FileListToArray($array_of_pathes, "*", 2)

; process elements of $SubDirs and append all elements to $array_of_pathes ; this may add some new elements

WEND

Rewriting it to AutoIT caused an runtime error because, at the beginning, the initialized array got emptied by the _arrayPop, which causes IsArray($array_of_pathes) to return 0.

While this can be avoided by introducing another element at index 0 and adopting the tests, it shows that at this time AutoIT does not support empty arrays.

If you change that behaviour you should definitely check all the UDF in _array and provide proper warnings about the changed behaviour. Nevertheless introducing empty arrays is a good idea IMHO!

Thanx for your work!

--

Greetings from Germany!

Dr. Uwe Frenz

Link to comment
Share on other sites

This is partly wrong: AutoIt does support empty arrays. It's just that you can't create empty arrays from within AutoIt, but they may result from calls to COM objects. So indeed, the best way to deal with the case is to test explicitely.

EDIT: as Melba pointed out!

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Moderators

jchd,

You meant to say that you CANNOT create empty arrays from within AutoIt - I hope. ;)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

So I was right.

If you change that behaviour

If? We got empty arrays in 3.3.9.5

Local $avArray[0]
ConsoleWrite(IsArray($avArray) & @LF)
ConsoleWrite(UBound($avArray) & @LF)

1

0

@jchd & Melba

Mmmk.

Link to comment
Share on other sites

Ah, I always forget the alpha is public!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Moderators

AdmiralAlkex,

Mea culpa. ;)

But how many members use the 3.3.9.5 alpha release? I confess I do not so that I do not (overly) confuse anyone who asks for help by suggesting solutions outside the current release (and beta if I must). :)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

AdmiralAlkex,

Mea culpa. Posted Image

But how many members use the 3.3.9.5 alpha release? I confess I do not so that I do not (overly) confuse anyone who asks for help by suggesting solutions outside the current release (and beta if I must). Posted Image

M23

I suppose you are right, but the alpha happens to be the best place to get empty arrays for now so....

Beards.

Link to comment
Share on other sites

Can AutoIt tell me the meaning of life?

Yes... but that's not until version 12.4.8.3.

Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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