Jump to content
kcvinu

Doubt about _ArrayAdd()

Recommended Posts

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

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

 


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

 

Share this post


Link to post
Share on other sites

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

_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

@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

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


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

 

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

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

    • By argumentum
      There is a _ArrayToString() but no _ArrayFromString().  ( searched in the forum and google )
      The example is based on the _ArrayToString() help file, to show the reconstruction of the array.
      #include <Array.au3> #include <MsgBoxConstants.au3> Local $aArray[20] For $i = 0 To 19 $aArray[$i] = $i Next _ArrayDisplay($aArray, "1D Array") MsgBox($MB_SYSTEMMODAL, "Items 1-7", _ArrayToString($aArray, @TAB, 1, 7)) ConsoleWrite('>' & _ArrayToString($aArray, @TAB, 1, 7) & '<' & @CRLF) _ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, @TAB, 1, 7), @TAB), "1D ArrayFromString") Local $aArray[10][10] For $i = 0 To 9 For $j = 0 To 9 $aArray[$i][$j] = $i & "-" & $j Next Next _ArrayDisplay($aArray, "2D Array") MsgBox($MB_SYSTEMMODAL, "Rows 4-7, cols 2-5", _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5)) ConsoleWrite('>' & _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5) & '<' & @CRLF) _ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5), " :: ", @CRLF), "2D ArrayFromString") ; au3.user.calltips.api: ; _ArrayFromString($sString , [$sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $iForce2D = 0]]]) Rebuild an array from _ArrayToString() Func _ArrayFromString($sString, $sDelim_Col = "|", $sDelim_Row = @CRLF, $iForce2D = 0,) ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/ If $sDelim_Col = Default Or String($sDelim_Col) = "" Then $sDelim_Col = "|" If $sDelim_Row = Default Or String($sDelim_Row) = "" Then $sDelim_Row = @CRLF $iForce2D = Int($iForce2D) Local $m, $n, $b, $c = StringSplit($sString, $sDelim_Row, 3) ; $STR_ENTIRESPLIT + $STR_NOCOUNT $b = StringSplit($c[0], $sDelim_Col, 3) If UBound($c) = 1 And Not $iForce2D Then Return $b Local $a[UBound($c)][UBound($b)] For $n = 0 To UBound($c) - 1 $b = StringSplit($c[$n], $sDelim_Col, 3) If UBound($b) > UBound($a, 2) Then Return SetError(1) For $m = 0 To UBound($b) - 1 $a[$n][$m] = $b[$m] Next Next Return $a EndFunc ;==>_ArrayFromString
      PS: so, how to save an array to an ini file ? ( small array, the limitations of an ini file still applies )
      #include <Array.au3>; For _ArrayDisplay() ; if you declare it, it will use it, else, use default ;Global $g_iniFile = @ScriptDir & "\ThisTest.ini" Example() Func Example() Local $n, $aTest, $aArray[3] = ["00", "one", "2"] ; if is not in the INI file, it will save it $aTest = IniGet("Test", $aArray) _ArrayDisplay($aTest, "1st") ; since is saved, it'll recall it $aTest = IniGet("Test") For $n = 0 To UBound($aTest) - 1 ; ..just to show the elements found as integer If IsInt($aTest[$n]) Then $aTest[$n] &= " = IsInt() = " & (IsInt($aTest[$n]) = 1) Next _ArrayDisplay($aTest, "2nd") EndFunc ;==>Example Func IniGet($sKey, $vDefault = Default, $sSection = "Settings") Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini" Local $v, $s = IniRead($ini, $sSection, $sKey, Chr(1)) If $s = Chr(1) Then If $vDefault == Default Then Return SetError(1, 0, "") Else IniSet($sKey, $vDefault, $sSection) Return $vDefault EndIf EndIf $v = StringLeft($s, 1) Switch $v Case "i" Return Int(StringTrimLeft($s, 2)) Case "a" Return _ArrayFromString(BinaryToString(StringTrimLeft($s, 2)), Chr(1), Chr(2)) Case "d" Return Binary(StringTrimLeft($s, 2)) Case Else Return String(StringTrimLeft($s, 2)) EndSwitch EndFunc ;==>IniGet Func IniSet($sKey, $vValue, $sSection = "Settings") Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini" If IsInt($vValue) Then $vValue = "i:" & $vValue ElseIf IsArray($vValue) Then $vValue = "a:" & StringToBinary(_ArrayToString($vValue, Chr(1), -1, -1, Chr(2))) ElseIf IsBinary($vValue) Then $vValue = "d:" & $vValue Else $vValue = "s:" & $vValue EndIf $vValue = IniWrite($ini, $sSection, $sKey, $vValue) Return SetError(@error, @extended, $vValue) EndFunc ;==>IniSet ; au3.user.calltips.api: ; _ArrayFromString($sString , [$sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $iForce2D = 0]]]) Rebuild an array from _ArrayToString() Func _ArrayFromString($sString, $sDelim_Col = "|", $sDelim_Row = @CRLF, $iForce2D = 0,) ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/ If $sDelim_Col = Default Or String($sDelim_Col) = "" Then $sDelim_Col = "|" If $sDelim_Row = Default Or String($sDelim_Row) = "" Then $sDelim_Row = @CRLF $iForce2D = Int($iForce2D) Local $m, $n, $b, $c = StringSplit($sString, $sDelim_Row, 3) ; $STR_ENTIRESPLIT + $STR_NOCOUNT $b = StringSplit($c[0], $sDelim_Col, 3) If UBound($c) = 1 And Not $iForce2D Then Return $b Local $a[UBound($c)][UBound($b)] For $n = 0 To UBound($c) - 1 $b = StringSplit($c[$n], $sDelim_Col, 3) If UBound($b) > UBound($a, 2) Then Return SetError(1) For $m = 0 To UBound($b) - 1 $a[$n][$m] = $b[$m] Next Next Return $a EndFunc ;==>_ArrayFromString
      PS2: https://www.autoitscript.com/trac/autoit/ticket/3696#ticket
    • 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  
    • 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)
×
×
  • Create New...