kcvinu

Doubt about _ArrayAdd()

11 posts in this topic

#1 ·  Posted (edited)

Hi all,

How to add 2 elements to a 2D array. This is my code, But not working.

Local $ResArray[0][1]   ; Declaring an empty array
Local $Elem1 = 10
Local $Elem2 = 20
_ArrayAdd($ResArray, $Elem1, 0) ; Trying to add first column
_ArrayAdd($ResArray, $Elem2, 1) ; Trying to add second column

_ArrayDisplay($ResArray)

This will only add the first element. 

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites



if you want to add a value to column 2 you should at least declare an array wit 2 columns....

try

Local $ResArray[0][2]

 

1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

kcvinu,

You have only 1 column in your 2d array, so how do you expect the function add an element in the a non-existent column?  Had you checked the @error return from the second call to _ArrayAdd (4 - $iStart outside array bounds) you would have discovered this in less time that it took to post.

#include <Array.au3>

Local $ResArray[0][2] ;  2 column array
Local $Elem1 = 10
Local $Elem2 = 20
_ArrayAdd($ResArray, $Elem1, 0)
_ArrayAdd($ResArray, $Elem2, 1)

_ArrayDisplay($ResArray)

M23

 

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks But this was eating my head. 

Sorry to say. This not what i want.

 

000108.jpg

I want 10 & 20 in one row.

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

_000109.thumb.jpg.ed76dd5b7db593b323b7d8At last this worked

Local $ResArray[0][2]
Local $Elem1 = 10
Local $Elem2 = 20
Local $temp = $Elem1 & "," & $Elem2

_ArrayAdd($ResArray, $temp, 0,",")

_ArrayDisplay($ResArray)

Is there any other way to do this

 

000109.jpg

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites
_ArrayAdd($ResArray, $Elem1 & "," & $Elem2, 0, ",")

:D

1 person likes this

Share this post


Link to post
Share on other sites

@mikell , Short form of my code. You will benefit one line and an extra variable.  :)


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

... even shorter  :idiot:

#include <Array.au3>
Local $ResArray[1][2] = [[10, 20]]
_ArrayDisplay($ResArray)

 

1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

kcvinu,

Or just use the default delimiter:

#include <Array.au3>

Local $ResArray[0][2] ;  2 column array
Local $Elem1 = 10
Local $Elem2 = 20
_ArrayAdd($ResArray, $Elem1 & "|" & $Elem2)

_ArrayDisplay($ResArray)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

@Melba23 Thanks.

@Chimp , Actually, that is not what i wanted. I need to populate a 2D array with this ArrayAdd function.


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

kcvinu,
I posted this - as a joke - because I can't imagine how to use _ArrayAdd in a shorter way, except as said Melba by using the default delimiter  :)

1 person likes this

Share this post


Link to post
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

  • Similar Content

    • AndyS01
      By AndyS01
      I just updated to the newest version of AutoIT and when I add a line of text containing "|" characters to my array using _ArrayAdd(), the array ends up with each element containing a part of my string broken at "|".   So, if I had a string like "A|B|C|D", and I did an _arrayAdd($ar, "A|B|C|D), my array then contains 6 elements: [0] = 5 [1] = A [2] = B [3] = C [4] = D   I see that the calling syntax in the old AutoIT version is quite different than the new syntax: old: _ArrayAdd(ByRef $avArray, $vValue)   new: _ArrayAdd ( ByRef $aArray, $vValue [, $iStart = 0 [, $sDelim_Item = "|" [, $sDelim_Row = @CRLF [, $hDataType = 0]]]] )   The new syntax is not backwards compatible.   Sample code: #include <Array.au3> global $ar, $str, $outstr = "" $str = "A|B|C|D" $ar = stringsplit("","") _ArrayAdd($ar, $str) $outstr &= ubound($ar) & @crlf for $x = 0 to ubound($ar) - 1      $outstr &= $ar[$x] & @CRLF Next msgbox(0, "INFO", $outstr) New Version info: Version 3.4.4   Jul 13 2014 20:07:38   Old Version info: Version 3.3.6    Dec 30 2013 15:53:31  
    • Tardis
      By Tardis
      Hi all Im still New To Autoit and would realy like some help ...

      I have gone through some examples and other code on the forum but now I am stuck
      see comments on what I want to do .
      #RequireAdmin #include <IE.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <String.au3> #include <Array.au3> Global $oIE = _IECreate("https://www.harryhomers.org/et/forum/viewtopic.php?f=89&t=4309", 0, 0, 1, 0) Global $oElements = _IETagNameAllGetCollection($oIE) Global $oID = _IEGetObjById($oIE, "p41827") Global $ListArray[1] #cs ; the list I want to get is 1 - 20 max 30 and there names . The DIV ID is p41827 <div class="content">HarryHomers can be found at 85.236.100.205:<span style="font-weight: bold">27960</span><br /><br /><ul>HH Bot Multi campaign **<br /><br />1. NAME 1<br />2. NAME 2<br />3. NAME 3<br />4. NAME 4<br /> 5. NAME 5<br />6. NAME 6<br />7. NAME 7<br />8. NAME 8<br />9. NAME 9<br />10. NAME 10<br />11. NAME 11<br />12. NAME 12<br />13. NAME 13<br />14. NAME 14<br /> 15. NAME 15<br />16. NAME 16<br />17. NAME 17<br />18. NAME 18<br />19. NAME 19<br />20. NAME 20<br /> </ul> #ce For $oElement in $oElements     Local $_sSourceTAG = $oElement.tagname     Local $_sSourceTEXT = $oElement.innerText     Local $_sSourceID = $oElement.id     Local $_sSourceHTML = $oElement.innerhtml     If $_sSourceID = "p41827" Then ;Test message box                 MsgBox($MB_SYSTEMMODAL, "MY TAG ID", "Innertext: "  & $_sSourceTAG & @CRLF & "id: " & $_sSourceID & @CRLF & "innerText: " & $_sSourceTEXT)                 MsgBox($MB_SYSTEMMODAL, "MY HTML", "Innerhtml: "  & "id: " & $_sSourceID & $_sSourceHTML)         $oData = _IEPropertyGet($oIE, "strong")         $Check = StringRight($oData, 11)         If $Check = "ohnDory</A>" Then ;Test message box             MsgBox($MB_SYSTEMMODAL, "SEARCH FOUND", "The characters are: " & $Check )             $ArraySplit1 = StringSplit($oData, ".")             For $ArrayItem in $ArraySplit1                 $ArrayItem = StringSplit($ArrayItem, "<BR>", 1)                 If $ArrayItem[0] > 1 Then                     If $ArrayItem[2] > 0 Then                         $ArrayItem[1] = StringStripWS($ArrayItem[1], 3)                         _ArrayAdd($ListArray, $ArrayItem[1])                     EndIf                 EndIf                 If StringInStr($ArrayItem[1], "</UL>") Then                     $POS = StringInStr($ArrayItem[1], "</UL>") - 1                     $String = StringLeft($ArrayItem[1], $POS)                     $String = StringStripWS($String, 3)                     _ArrayAdd($ListArray, $String)                 EndIf             Next         Else ; Not correct so ignore         MsgBox($MB_SYSTEMMODAL, "NOT FOUND", "The characters are: " & $Check )         EndIf     EndIf     Next     _ArrayDisplay($ListArray)     _ArrayReverse($ListArray)     _ArrayPop($ListArray)     _ArrayReverse($ListArray)     _ArrayDisplay($ListArray, "Map List Array Final View")     sleep(2500) _IEQuit($oIE) #cs ; note the html (map names) does change once a month ; save txt file #ce ;_FileWriteLog(@TempDir & "\list.txt", $ListArray)