Jump to content
dynamitemedia

xmldom into array and then use outside function

Recommended Posts

i have the following snippet...   now its working but i have it inside a function and want to be able to use   $aThumb[$i]  outside the function in the rest of the script, i tried return and keep getting this error  "Invalid keyword at the start of this line.:"  

Global $iRows = UBound($a, $UBOUND_ROWS) 
    Global $iCols = UBound($a, $UBOUND_COLUMNS)

          $oID = $oID + 1
          $oURL = $oString.selectSingleNode("./url")
          $oName = $oString.selectSingleNode("./name")
          $oCategory = $oString.selectSingleNode("./category")
          $oThumb = $oString.selectSingleNode("./image")
          $oLanguage = $oString.selectSingleNode("./language")

         $aThumb = [$iRows]
         _ArrayAdd($aThumb, $oThumb.text)

         For $i = 1 To UBound($aThumb) - 1
             ConsoleWrite($oID & @TAB & $aThumb[$i] & @CRLF)
         Next
          
    Next
   ConsoleWrite( "rows: " & $iRows & @CRLF)

Thanks for your help

Share this post


Link to post
Share on other sites

Have you ever heard that functions can return a result? No, then smiley38.gif (Language Reference - User Functions)

Or show your (yet not) runable script, how you tried it.

Edited by AutoBert

Share this post


Link to post
Share on other sites

wow no need to be answer only to be rude...     thought was such a general question i had given enough info

Global Enum $iServerName, $iUBound

      Local $sText = ""
      For $i = 1 To Random(5, 20, 1)
         $sText &= Chr(Random(65, 122, 1))
      Next

       $link = "http://www.my site.to/api/live.xml?t=" & $sText   ; private api 
      ConsoleWrite($link  & @CRLF)

       Local $dBinary = InetRead($link)
       $sConverted = BinaryToString($dBinary)


       $strXMLStructure = "//channels/channel"
       $oXML = ObjCreate("Microsoft.XMLDOM")
       $oXML.loadXML($sConverted)

       $oStrings = $oXML.selectNodes($strXMLStructure)


       $oID = 0

Local $a
      For $oString In $oStrings

       If IsArray($a) Then
        ReDim $a[UBound($a)+1][$iUBound]
    Else
        Local $a[1][$iUBound]
    EndIf


    Global $iRows = UBound($a, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10.
    Global $iCols = UBound($a, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20.

          $oID = $oID + 1
          $oURL = $oString.selectSingleNode("./url")
          $oName = $oString.selectSingleNode("./name")
          $oCategory = $oString.selectSingleNode("./category")
          $oThumb = $oString.selectSingleNode("./image")
          $oLanguage = $oString.selectSingleNode("./language")

         Local $aThumb = [$iRows]
         _ArrayAdd($aThumb, $oThumb.text)

         For $i = 1 To UBound($aThumb) - 1
             ;ConsoleWrite($oID & @TAB & $aThumb[$i] & @CRLF)
            local $bThumb = 22
         Next
          ; ConsoleWrite($oID & @TAB & $oName.text & @TAB & $urlString & @TAB & $oThumb.text & @TAB & $oCategory.text & @TAB & $oLanguage.text & @CRLF )

            Return $bThumb

           Next

   ConsoleWrite( "rows: " & $iRows & @CRLF)

 

Share this post


Link to post
Share on other sites

dymanitemedia,

"Return" is not allowed from GLOBAL scope, meaning that it is only used within a function, normally to return a value to the caller.

Your code is not runnable as several vars are undefined, perhaps some includes are missing?

kylomas

Also, I would make sure that $ostrings is an object and what are you trying to do with variable $a?

Edited by kylomas
additional info

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

sorry the includes did get missed!  full code is here:
 

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Process.au3>
#include <Constants.au3>
#include <String.au3>
#include <Date.au3>

Global Enum $iServerName, $iUBound

      Local $sText = ""
      For $i = 1 To Random(5, 20, 1)
         $sText &= Chr(Random(65, 122, 1))
      Next

       $link = "http://my private api /api/live.xml?t=" & $sText
      ConsoleWrite($link  & @CRLF)

       Local $dBinary = InetRead($link)
       $sConverted = BinaryToString($dBinary)


       $strXMLStructure = "//channels/channel"
       $oXML = ObjCreate("Microsoft.XMLDOM")
       $oXML.loadXML($sConverted)

       $oStrings = $oXML.selectNodes($strXMLStructure)


       $oID = 0

Local $a
      For $oString In $oStrings

       If IsArray($a) Then
        ReDim $a[UBound($a)+1][$iUBound]
    Else
        Local $a[1][$iUBound]
    EndIf


    Global $iRows = UBound($a, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10.
    Global $iCols = UBound($a, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20.

          $oID = $oID + 1
          $oURL = $oString.selectSingleNode("./url")

          $oName = $oString.selectSingleNode("./name")
          $oCategory = $oString.selectSingleNode("./category")
          $oThumb = $oString.selectSingleNode("./image")
          $oLanguage = $oString.selectSingleNode("./language")

         Local $aThumb = [$iRows]
         _ArrayAdd($aThumb, $oThumb.text)

         For $i = 1 To UBound($aThumb) - 1
             ;ConsoleWrite($oID & @TAB & $aThumb[$i] & @CRLF)
            local $bThumb = 22
         Next
          ; ConsoleWrite($oID & @TAB & $oName.text & @TAB & $urlString & @TAB & $oThumb.text & @TAB & $oCategory.text & @TAB & $oLanguage.text & @CRLF )

            Return $bThumb

           Next

   ConsoleWrite( "rows: " & $iRows & @CRLF)

I need the thumbs , all of them in the gui...  the thing is i want to be able to grab more this just this xml, if it was meant to ONLY use one xml file i can hard code it work just fine...  but each api will have different xml structure and i need to code to work with each one
 

 

EDIT/ Additions

the $a is used to get the count of rows and columns

i use the rows to know how many buttons i will need to make

Edited by dynamitemedia
adding what $a is for

Share this post


Link to post
Share on other sites

@jdelaney

Since you see, the expert at using the xml dom, any ideas how i can do this... I would really like to put this above in a function and still use each of the xml nodes if needed say i click on button 56  it would go to node 56 and get that info

Share this post


Link to post
Share on other sites

Seeing your script in #5 and checking:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /prod /AU3Check /in "C:\Users\Bert\AutoIt3.My\Test\jhgfddfgh.au3"
+>12:43:50 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000407  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0407)
+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.1)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Test\jhgfddfgh.au3
"C:\Users\Bert\AutoIt3.My\Test\jhgfddfgh.au3"(71,27) : error: 'Return' not allowed from global scope.
            Return $bThumb
~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Test\jhgfddfgh.au3 - 1 error(s), 0 warning(s)
!>12:43:53 AU3Check ended. Press F4 to jump to next error.rc:2
+>12:43:53 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 5.195

i am wondering about your ignorance.:

On ‎28‎.‎01‎.‎2016 at 10:31 PM, kylomas said:

"Return" is not allowed from GLOBAL scope, meaning that it is only used within a function, normally to return a value to the caller.

 This snippet:

Local $a
      For $oString In $oStrings

       If IsArray($a) Then
        ReDim $a[UBound($a)+1][$iUBound]
    Else
        Local $a[1][$iUBound]
    EndIf

show's me:

  • there you need the to learn the basic's. A variable $a just declared without any dimension testing against Array is nonsence. It couldn't be a array, nothing is happend.  So smiley38.gif work hard from the beginning to the end, including testing the examples of the needed functions.
  • or your script isn't complete, then post your complete script. 

Share this post


Link to post
Share on other sites

AutoBert,

You have already been told once today about the manner in which you are replying - this is the second and final warning you get to change your ways. If your RTFM emoticon appears again - or if you express a similar unwelcoming attitude in future - your future in this community will be in serious jeopardy.

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

these are help forums to ask for help..  why do you feel the need to insult and be rude to people asking for help?

that snippet that shows you   with your rant  was taken from here and it serves a purpose
https://www.autoitscript.com/forum/topic/179751-searching-fields-within-xml/?do=findComment&comment=1290314

I use it to get how many noded(rows) in the array

Global $iRows = UBound($a, $UBOUND_ROWS)

it works, is it right i am not 100% sure  but that works with giving me the right amount of nodes from the XML

as far as leaving the "Return" in there i  did uncomment it in my code.

and it is the whole code and works, when connected to the right  xml.   

I just want to make this a function  cause the images in the nodes will complete the gui.  

Instead of being rude maybe offering a alternate solution would be the way to go

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 Malkey
      _ArrayMultiSort - This function sorts many columns (with optional case sensitivity, ascending or descending, and in any specific order) of an array.

      The following three functions _ArraySort,  __ArrayQuickSort1D,  and __ArrayQuickSort2D from the Array.au3 include file had to be modified to allow case sensitive sorting.
      The modified functions are renamed by appending a "C" for "Case" to each function's name giving _ArraySortC, __ArrayQuickSort1DC, and __ArrayQuickSort2DC. 
      The modifications involve each of these functions having a trailing parameter, $iCase, added, and, within these functions wherever the function "StringCompare" occurs, its third parameter, $iCase, is inserted. So when $iCase = 0, StringCompare is not case sensitive.  When $iCase = 1, StringCompare is case sensitive.
      Here is the UDF containing the functions used to sort arrays with case sensitivity.
      ArrayMultiSortCase.au3
      #include-once ; https://www.autoitscript.com/forum/topic/198148-_arraymultisort-sort-multiple-columns-with-case-sensitivity/ ; File Name: #include <ArrayMultiSortCase.au3> ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; #INCLUDES# ========================================================================================================= #include <Array.au3> ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayMultiSort ; Description ...: Sort a 1D or, sort a 2D array with the ability to specify which columns to sort and which direction to sort for each column. ; Syntax.........: _ArrayMultiSort(ByRef $avArray[, $sSort = '0a'[, $iStartRow = 0[, $iEndRow = 0]]]) ; Parameters ....: $avArray - Array to sort ; $sSort - [optional] The default setting only sorts the first column, column 0, in ascending order. Otherwise, $sSort is ; a string made up of comma separated column descriptors which contains a column number, sort direction and case ; sensitivity for that column. These 3 fields can be in any order in the column descriptor. Each column ; descriptor shows the sort order of columns of the array from left to right. ; "a" - Ascending order 0-9,A-Z,a-z (Without "a" or "d" default is "a") ; "d" - Descending order z-a,Z-A,9-0 ; "c" - sort that column with case sensitivity. ; No "c" present, that column is sorted with case insensitivity (default). ; Within the column descriptors, spaces are optional; and, ; Upper or lower case column descriptors, "CAD" or "cad", are recognized as the same - use either. ; Examples of the $sSort variable:- ; "3 ac, CD2, 0C, d1" -> First sort col#3 (case sensitive, ascending). ; Secondly sort col#2 (case sensitive, descending). ; Thirdly sort col#0 (case sensitive, ascending[default]). ; Lastly sort col#1 (case insensitive[default], descending). ; "0" or "" -> Sort col#0 (case insensitive[default], ascending[default]). ; See https://www.autoitscript.com/forum/topic/198148-_arraysort-_arraymultisort-with-case-sensitivity/?do=findComment&comment=1422656 ; $iStartRow - [optional] Row index of array to start sorting at. ; $iEndRow - [optional] Row index of array to stop sorting at. ; Return values .: Success - 1 ; Failure - 0, @error set to the same as returned from _ArraySort() function. (See _ArraySort in AutoIt help file) ; Author ........: Malkey ; Modified.......: ; Remarks .......: Updated version from https://www.autoitscript.com/forum/topic/166426-_filelisttoarray-sorting/?do=findComment&comment=1216234 ; This function requires the __TestExp function, and #Include <Array.au3> and the case sensitive versions of _ArraySort, ; __ArrayQuickSort1D, and __ArrayQuickSort2D. ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _ArrayMultiSort(ByRef $aArray, $sSort = '0a', $iStartRow = 0, $iEndRow = 0) Local $iCol1, $Dir, $iLastRow, $iStart, $iRetV, $iEnd, $Err, $aSort2D[0][3] ;------------ $sSort (string) to $aSort2D (array) ----------- _ArrayAdd($aSort2D, Execute(StringTrimRight(StringRegExpReplace(StringStripWS($sSort, 8), "(?i)(c)(\d+)([ad]),?|([ad])(\d+)(c),?" & _ ; RE pattern 2 possibilities (BackRef 1 to 6) "|(\d+)([ad])(c),?|(\d+)(c)([ad]),?|([ad])(c)(\d+),?|(c)([ad])(\d+),?|([ad])(\d+),?|(c)(\d+),?|(\d+)(c),?|(\d+)([ad]),?|(\d+),?", _ ; RE pattern 9 possibilities (BackRef 7 to 27) "('$1$6$9${11}${14}${16}${21}${24}'='c')*1&""|$2$5$7${10}${15}${18}${20}${22}${23}${25}${27}|""&('$3$4$8${12}${13}${17}${19}${26}'='d')*1&@CRLF&"), _ ; The 'replace' parameter of StringRegExpReplace() 7))) ; End of StringTrimRight() that removes trailing "&@CRLF&" ;_ArrayDisplay($aSort2D, "", "", 0, Default, "Case|Col#|Asc/Desc") ; ------------------------------------------------------------ If $iEndRow = 0 Or ($iEndRow > (UBound($aArray) - 1)) Then $iLastRow = UBound($aArray) - 1 $iStart = -1 $iEnd = -1 ; Sort the first column to be sorted. $iRetV = _ArraySortC($aArray, Number($aSort2D[0][2]), $iStartRow, $iLastRow, Number($aSort2D[0][1]), 0, Number($aSort2D[0][0])) ; Sort on the first column (stored in $aSort2D[0][1]) $Err = @error If $iRetV = 0 Then Return SetError($Err, 0, 0) ; Sort all remaining columns. For $j = 1 To UBound($aSort2D) - 1 ; For each group of equal values in the previous sorted column, sort the present column values on the same rows of each group. $iStart = -1 For $i = $iStartRow To $iLastRow Switch $i Case $iStartRow If $i <> $iLastRow Then If __TestExp($aArray, $aSort2D, $i, $j) Then $iStart = $i + 1 $iEnd = $i + 1 Else $iStart = $i $iEnd = $i + 1 EndIf EndIf Case $iLastRow $iEnd = $iLastRow If $iStart <> $iEnd Then $iRetV = _ArraySortC($aArray, Number($aSort2D[$j][2]), $iStart, $iEnd, Number($aSort2D[$j][1]), 0, Number($aSort2D[$j][0])) $Err = @error EndIf Case Else If __TestExp($aArray, $aSort2D, $i, $j) Then $iEnd = $i If $iStart <> $iEnd Then $iRetV = _ArraySortC($aArray, Number($aSort2D[$j][2]), $iStart, $iEnd, Number($aSort2D[$j][1]), 0, Number($aSort2D[$j][0])) $Err = @error EndIf $iStart = $i + 1 $iEnd = $iStart Else $iEnd = $i EndIf EndSwitch Next Next Return SetError($Err, 0, $iRetV) EndFunc ;==>_ArrayMultiSort ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __TestExp ; Description ...: Creates and tests a test expression. Internally used function by the _ArrayMultiSort() function ; Syntax.........: __TestExp($aA, $aC, $k, $m) ; Parameters ....: $aA - The 2D array to be sorted. ; $aC - A 2D array containing to column sorting order and each column's direction of sorting.(See Modified note) ; $k - The array's row index of the data being sorted. ; $m - The array's row index of the current column being sorted ; Return values .: 1 - When any of the created test expressions are true; or, ; 0 - When all of the created test expressions are false. ; Author ........: Malkey ; Modified.......: Malkey 2019/3/9 Array $aC is now [n][3] where [n][0] is case sensitivity; [n][1] is Column#; [n][2] is sort asc or desc. ; Remarks .......: This function is used internally by the _ArrayMultiSort function. The created expression tests the particular ; row, $k, of the test data, for each previously sorted column, $m -1, wheather the value in that column, $aA[$k][$aC[$w][1]], ; is not equal to the next value in that same column, $aA[$k + 1][$aC[$w][1]], where $aC[$w][1] contains the previously sorted column number. ; =============================================================================================================================== Func __TestExp(ByRef $aA, ByRef $aC, $k, $m) For $w = 0 To $m - 1 If ($aA[$k + 1][$aC[$w][1]]) <> ($aA[$k][$aC[$w][1]]) Then ; Like an "Or" join statements. If just one of the expressions in the For-Next loop is true, then function returns "1" (True). Return 1 EndIf Next Return 0 EndFunc ;==>__TestExp ; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ; =============================================================================================== ; The following three function, ; _ArraySortC, __ArrayQuickSort1DC, and __ArrayQuickSort2DC are modied copies of the functions, ; _ArraySort, __ArrayQuickSort1D, and __ArrayQuickSort2D from the Array.au3 include file. ; The modifications allow case sensitive sorting of arrays. ; =============================================================================================== ; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ; #FUNCTION# ==================================================================================================================== ; Author ........: Jos ; Modified.......: LazyCoder - added $iSubItem option; Tylo - implemented stable QuickSort algo; Jos - changed logic to correctly Sort arrays with mixed Values and Strings; Melba23 - implemented stable pivot algo; Malkey - added case sensitive sorting. ; =============================================================================================================================== Func _ArraySortC(ByRef $aArray, $iDescending = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0, $iPivot = 0, $iCase = 0) If $iDescending = Default Then $iDescending = 0 If $iStart = Default Then $iStart = 0 If $iEnd = Default Then $iEnd = 0 If $iSubItem = Default Then $iSubItem = 0 If $iPivot = Default Then $iPivot = 0 If $iCase = Default Then $iCase = 0 If Not IsArray($aArray) Then Return SetError(1, 0, 0) Local $iUBound = UBound($aArray) - 1 If $iUBound = -1 Then Return SetError(5, 0, 0) ; Bounds checking If $iEnd = Default Then $iEnd = 0 If $iEnd < 1 Or $iEnd > $iUBound Or $iEnd = Default Then $iEnd = $iUBound If $iStart < 0 Or $iStart = Default Then $iStart = 0 If $iStart > $iEnd Then Return SetError(2, 0, 0) ; Sort Switch UBound($aArray, $UBOUND_DIMENSIONS) Case 1 If $iPivot Then ; Switch algorithms as required __ArrayDualPivotSort($aArray, $iStart, $iEnd) Else __ArrayQuickSort1DC($aArray, $iStart, $iEnd, $iCase) EndIf If $iDescending Then _ArrayReverse($aArray, $iStart, $iEnd) Case 2 If $iPivot Then Return SetError(6, 0, 0) ; Error if 2D array and $iPivot Local $iSubMax = UBound($aArray, 2) - 1 ; $UBOUND_COLUMNS (2) If $iSubItem > $iSubMax Then Return SetError(3, 0, 0) If $iDescending Then $iDescending = -1 Else $iDescending = 1 EndIf __ArrayQuickSort2DC($aArray, $iDescending, $iStart, $iEnd, $iSubItem, $iSubMax, $iCase) Case Else Return SetError(4, 0, 0) EndSwitch Return 1 EndFunc ;==>_ArraySortC ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __ArrayQuickSort1DC (Appended 'C' for case sensitivity) ; Description ...: Helper function for sorting 1D arrays ; Syntax.........: __ArrayQuickSort1D ( ByRef $aArray, ByRef $iStart, ByRef $iEnd ) ; Parameters ....: $aArray - Array to sort ; $iStart - Index of array to start sorting at ; $iEnd - Index of array to stop sorting at ; Return values .: None ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima ; Modified.......: Malkey ; Remarks .......: For Internal Use Only. All StringCompare functions have $iCase parameter added for optional case sensitivity. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func __ArrayQuickSort1DC(ByRef $aArray, Const ByRef $iStart, Const ByRef $iEnd, Const ByRef $iCase) If $iEnd <= $iStart Then Return Local $vTmp ; InsertionSort (faster for smaller segments) If ($iEnd - $iStart) < 15 Then Local $vCur For $i = $iStart + 1 To $iEnd $vTmp = $aArray[$i] If IsNumber($vTmp) Then For $j = $i - 1 To $iStart Step -1 $vCur = $aArray[$j] ; If $vTmp >= $vCur Then ExitLoop If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur, $iCase) >= 0) Then ExitLoop $aArray[$j + 1] = $vCur Next Else For $j = $i - 1 To $iStart Step -1 If (StringCompare($vTmp, $aArray[$j], $iCase) >= 0) Then ExitLoop $aArray[$j + 1] = $aArray[$j] Next EndIf $aArray[$j + 1] = $vTmp Next Return EndIf ; QuickSort Local $L = $iStart, $R = $iEnd, $vPivot = $aArray[Int(($iStart + $iEnd) / 2)], $bNum = IsNumber($vPivot) Do If $bNum Then ; While $aArray[$L] < $vPivot While ($aArray[$L] < $vPivot And IsNumber($aArray[$L])) Or (Not IsNumber($aArray[$L]) And StringCompare($aArray[$L], $vPivot, $iCase) < 0) $L += 1 WEnd ; While $aArray[$R] > $vPivot While ($aArray[$R] > $vPivot And IsNumber($aArray[$R])) Or (Not IsNumber($aArray[$R]) And StringCompare($aArray[$R], $vPivot, $iCase) > 0) $R -= 1 WEnd Else While (StringCompare($aArray[$L], $vPivot, $iCase) < 0) $L += 1 WEnd While (StringCompare($aArray[$R], $vPivot, $iCase) > 0) $R -= 1 WEnd EndIf ; Swap If $L <= $R Then $vTmp = $aArray[$L] $aArray[$L] = $aArray[$R] $aArray[$R] = $vTmp $L += 1 $R -= 1 EndIf Until $L > $R __ArrayQuickSort1DC($aArray, $iStart, $R, $iCase) __ArrayQuickSort1DC($aArray, $L, $iEnd, $iCase) EndFunc ;==>__ArrayQuickSort1DC ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __ArrayQuickSort2DC (Appended 'C' for case sensitivity) ; Description ...: Helper function for sorting 2D arrays ; Syntax.........: __ArrayQuickSort2D ( ByRef $aArray, ByRef $iStep, ByRef $iStart, ByRef $iEnd, ByRef $iSubItem, ByRef $iSubMax ) ; Parameters ....: $aArray - Array to sort ; $iStep - Step size (should be 1 to sort ascending, -1 to sort descending!) ; $iStart - Index of array to start sorting at ; $iEnd - Index of array to stop sorting at ; $iSubItem - Sub-index to sort on in 2D arrays ; $iSubMax - Maximum sub-index that array has ; Return values .: None ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima ; Modified.......: Malkey ; Remarks .......: For Internal Use Only. All StringCompare functions have $iCase parameter added for optional case sensitivity. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func __ArrayQuickSort2DC(ByRef $aArray, Const ByRef $iStep, Const ByRef $iStart, Const ByRef $iEnd, Const ByRef $iSubItem, Const ByRef $iSubMax, Const ByRef $iCase) If $iEnd <= $iStart Then Return ; QuickSort Local $vTmp, $L = $iStart, $R = $iEnd, $vPivot = $aArray[Int(($iStart + $iEnd) / 2)][$iSubItem], $bNum = IsNumber($vPivot) Do If $bNum Then ; While $aArray[$L][$iSubItem] < $vPivot While ($iStep * ($aArray[$L][$iSubItem] - $vPivot) < 0 And IsNumber($aArray[$L][$iSubItem])) Or (Not IsNumber($aArray[$L][$iSubItem]) And $iStep * StringCompare($aArray[$L][$iSubItem], $vPivot, $iCase) < 0) $L += 1 WEnd ; While $aArray[$R][$iSubItem] > $vPivot While ($iStep * ($aArray[$R][$iSubItem] - $vPivot) > 0 And IsNumber($aArray[$R][$iSubItem])) Or (Not IsNumber($aArray[$R][$iSubItem]) And $iStep * StringCompare($aArray[$R][$iSubItem], $vPivot, $iCase) > 0) $R -= 1 WEnd Else While ($iStep * StringCompare($aArray[$L][$iSubItem], $vPivot, $iCase) < 0) $L += 1 WEnd While ($iStep * StringCompare($aArray[$R][$iSubItem], $vPivot, $iCase) > 0) $R -= 1 WEnd EndIf ; Swap If $L <= $R Then For $i = 0 To $iSubMax $vTmp = $aArray[$L][$i] $aArray[$L][$i] = $aArray[$R][$i] $aArray[$R][$i] = $vTmp Next $L += 1 $R -= 1 EndIf Until $L > $R __ArrayQuickSort2DC($aArray, $iStep, $iStart, $R, $iSubItem, $iSubMax, $iCase) __ArrayQuickSort2DC($aArray, $iStep, $L, $iEnd, $iSubItem, $iSubMax, $iCase) EndFunc ;==>__ArrayQuickSort2DC Here is an example using the _ArrayMultiSort function.
      #include <ArrayMultiSortCase.au3> ;#cs ; --------------- Create test data -------------- Global $array[2001][5] = [["Col 0", "Col 1", "Col 2", "Col 3", "Col 4"]] ; For $i = 1 To 2000 $array[$i][0] = (Random(0, 1, 1) ? Chr(Random(97, 99, 1)) : Chr(Random(65, 67, 1))) $array[$i][1] = (Random(0, 1, 1) ? Chr(Random(97, 99, 1)) : Chr(Random(65, 67, 1))) $array[$i][2] = (Random(0, 1, 1) ? Int(Random(0, 2, 1) & Random(1, 3, 1)) : (Random(0, 1, 1) ? Chr(Random(97, 99, 1)) : Chr(Random(65, 67, 1)))) $array[$i][3] = Random(1, 5, 1) $array[$i][4] = Random(1, 5, 1) Next ; -----------> End of Create test data ----------- Local $aArray = $array ; Sort column 0(asc+case sensitive) then column 1(desc+case insensitive), then columns 2(asc+case sensitive), 3(desc+case insensitive), and 4(asc+case insensitive). _ArrayMultiSort($aArray, "c0a,1d,c2a,3d,4a", 1) _ArrayDisplay($aArray, "Sorted c0a,1d,c2a,3d,4a") Local $aArray = $array _ArrayMultiSort($aArray, "1d, c0, c2d, 3, 4d", 1) ; Sort column 1(desc) then column 0(asc+case sensitive), then columns 2(desc+case sensitive), 3(asc), and 4(desc). _ArrayDisplay($aArray, "Sorted 1d,c0a,c2d,3a,4d") ;#ce ;#cs Local $a_Test[18][2] = [["Color", "#"], ["Black", 3], ["Blue", 3], ["white", 3], ["Brown", 4], ["Clear", 3], ["Gold", 3], ["gold", 3], _ ["green", 3], ["Green", 3], ["brown", 4], ["Purple", 3], ["Red", 3], ["Royal", 3], ["Silver", 2], ["Sky", 2], ["White", 3], ["Yellow", 5]] _ArrayDisplay($a_Test, "Unsorted") _ArrayMultiSort($a_Test, "1d,0a", 1) ; Sort Column 1 descending, then Column 0 ascending _ArrayDisplay($a_Test, "Sorted 1d,0a Starting @ row1") _ArrayMultiSort($a_Test, "1d,c0a", 1) ; Sort Column 1 descending, then Column 0 ascending+case sensitive _ArrayDisplay($a_Test, "Sorted 1d,c0a Starting @ row1") ;#ce ;#cs Local $aTest[] = [2, "Black", "Blue", 3, "Brown", 4, "Clear", 3, "Gold", 3, "green", 13, "Gray", 3, "gold", 23, "Green", 3, "gray", 33, "Purple", 3, "Red", 3, "Royal", 3, "Silver", 2, "Sky", 2, "White", 3, "Yellow", 5] _ArrayMultiSort($aTest, 'c0a') _ArrayDisplay($aTest, "Sorted c0a") ;#ce  
      Here is an example to test the _ArraySortC function which is the same as _ArraySort function, but with an extra parameter "$iCase" added.
      #include <ArrayMultiSortCase.au3> Local $array[9][3] = [ _ ["age", 40, 8], _ [1, 32, 7], _ [4, 16, 9], _ ["ace", 32, 7], _ ["ass", 16, 9], _ [35, 32, 7], _ [24, 16, 9], _ ["Ama", 5, 0], _ ["Aft", 19, 6]] Local $avArray = $array ;_ArrayDisplay($avArray, "$avArray BEFORE _ArraySort()") _ArraySortC($avArray) ;, 0, 0, 0, 0, 0) _ArrayDisplay($avArray, "Asc col0") $avArray = $array _ArraySortC($avArray, 0, 0, 0, 0, 0, 1) _ArrayDisplay($avArray, "Asc col0; case-sensitive") $avArray = $array _ArraySortC($avArray, 1, 0, 0, 0, 0, 1) _ArrayDisplay($avArray, "Desc col0; case-sensitive") $avArray = $array _ArraySortC($avArray, 1, 1, 0, 0, 0, 1) _ArrayDisplay($avArray, "Start row1; Desc col0; case-sensitive")  
    • By TrashBoat
      Im trying to iterate through a 2d array created by 
      ProcessList() function that returns a 2d array containing names and pid's, i wanted to filter through the names and delete entries that have "svchost.exe" and this is how i did it
      Func _Sanitize($array) For $x = 1 To UBound($array) - 1 ConsoleWrite($array[$x][0] & @CRLF) If $array[$x][0] == "svchost.exe" Then _ArrayDelete($array, $x) EndIf Next EndFunc ;==>_Sanitize And i get this error message
      What is wrong?
    • By TheDcoder
      Hello Guys! I wanted to share all my knowledge on arrays! Hope may enjoy the article , Lets start!
      Declaring arrays!
      Declaring arrays is a little different than other variables: 
      ; Rules to follow while declaring arrays: ; ; Rule #1: You must have a declarative keyword like Dim/Global/Local before the declaration unless the array is assigned a value from a functions return (Ex: StringSplit) ; Rule #2: You must declare the number of dimensions but not necessarily the size of the dimension if you are gonna assign the values at the time of declaration. #include <Array.au3> Local $aEmptyArray[0] ; Creates an Array with 0 elements (aka an Empty Array). Local $aArrayWithData[1] = ["Data"] _ArrayDisplay($aEmptyArray) _ArrayDisplay($aArrayWithData) That's it
      Resizing Arrays
      Its easy! Just like declaring an empty array! ReDim is our friend here:
      #include <Array.au3> Local $aArrayWithData[1] = ["Data1"] ReDim $aArrayWithData[2] ; Change the number of elements in the array, I have added an extra element! $aArrayWithData[1] = "Data2" _ArrayDisplay($aArrayWithData) Just make sure that you don't use ReDim too often (especially don't use it in loops!), it can slow down you program.
      Best practice of using "Enum"
      You might be wondering what they might be... Do you know the Const keyword which you use after Global/Local keyword? Global/Local are declarative keywords which are used to declare variables, of course, you would know that already by now , If you check the documentation for Global/Local there is a optional parameter called Const which willl allow you to "create a constant rather than a variable"... Enum is similar to Const, it declares Integers (ONLY Integers):
      Global Enum $ZERO, $ONE, $TWO, $THREE, $FOUR, $FIVE, $SIX, $SEVEN, $EIGHT, $NINE ; And so on... ; $ZERO will evaluate to 0 ; $ONE will evaluate to 1 ; You get the idea :P ; Enum is very useful to declare Constants each containing a number (starting from 0) This script will demonstrate the usefulness and neatness of Enums :
      ; We will create an array which will contain details of the OS Global Enum $ARCH, $TYPE, $LANG, $VERSION, $BUILD, $SERVICE_PACK Global $aOS[6] = [@OSArch, @OSType, @OSLang, @OSVersion, @OSBuild, @OSServicePack] ; Now, if you want to access anything related to the OS, you would do this: ConsoleWrite(@CRLF) ConsoleWrite('+>' & "Architecture: " & $aOS[$ARCH] & @CRLF) ConsoleWrite('+>' & "Type: " & $aOS[$TYPE] & @CRLF) ConsoleWrite('+>' & "Langauge: " & $aOS[$LANG] & @CRLF) ConsoleWrite('+>' & "Version: " & $aOS[$VERSION] & @CRLF) ConsoleWrite('+>' & "Build: " & $aOS[$BUILD] & @CRLF) ConsoleWrite('+>' & "Service Pack: " & $aOS[$SERVICE_PACK] & @CRLF) ConsoleWrite(@CRLF) ; Isn't it cool? XD You can use this in your UDF(s) or Program(s), it will look very neat!
      Looping through an Array
      Looping through an array is very easy! . There are 2 ways to loop an array in AutoIt!
      Simple Way:
      ; This is a very basic way to loop through an array ; In this way we use a For...In...Next Loop! Global $aArray[2] = ["Foo", "Bar"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $vElement In $aArray ; $vElement will contain the value of the elements in the $aArray... one element at a time. ConsoleWrite($vElement & @CRLF) ; Prints the element out to the console Next ; And that's it! Advanced Way:
      ; This is an advanced way to loop through an array ; In this way we use a For...To...Next Loop! Global $aArray[4] = ["Foo", "Bar", "Baz", "Quack"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $i = 0 To UBound($aArray) - 1 ; $i is automatically created and is set to zero, UBound($aArray) returns the no. of elements in the $aArray. ConsoleWrite($aArray[$i] & @CRLF) ; Prints the element out to the console. Next ; This is the advanced way, we use $i to access the elements! ; With the advanced method you can also use the Step keyword to increase the offset in each "step" of the loop: ; This will only print every 2nd element starting from 0 ConsoleWrite(@CRLF & "Every 2nd element: " & @CRLF) For $i = 0 To UBound($aArray) - 1 Step 2 ConsoleWrite($aArray[$i] & @CRLF) Next ; This will print the elements in reverse order! ConsoleWrite(@CRLF & "In reverse: " & @CRLF) For $i = UBound($aArray) - 1 To 0 Step -1 ConsoleWrite($aArray[$i] & @CRLF) Next ; And that ends this section! For some reason, many people use the advance way more than the simple way . For more examples of loops see this post by @FrancescoDiMuro!
      Interpreting Multi-Dimensional Arrays
      Yeah, its the most brain squeezing problem for newbies, Imagining an 3D Array... I will explain it in a very simple way for ya, so stop straining you brain now! . This way will work for any array regardless of its dimensions...
      Ok, Lets start... You can imagine an array as a (data) mine of information:

      ; Note that: ; Dimension = Level (except the ground level :P) ; Element in a Dimension = Path ; Level 2 ----------\ ; Level 1 -------\ | ; Level 0 ----\ | | ; v v v Local $aArray[2][2][2] ; \-----/ ; | ; v ; Ground Level ; As you can see that $aArray is the Ground Level ; All the elements start after the ground level, i.e from level 0 ; Level 0 Contains 2 different paths ; Level 1 Contains 4 different paths ; Level 2 Contains 8 different paths ; When you want too fill some data in the data mine, ; You can do that like this: $aArray[0][0][0] = 1 $aArray[0][0][1] = 2 $aArray[0][1][0] = 3 $aArray[0][1][1] = 4 $aArray[1][0][0] = 5 $aArray[1][0][1] = 6 $aArray[1][1][0] = 7 $aArray[1][1][1] = 8 ; Don't get confused with the 0s & 1s, Its just tracing the path! ; Try to trace the path of a number with the help of the image! Its super easy! :D I hope you might have understand how an array looks, Mapping your way through is the key in Multi-Dimensional arrays, You take the help of notepad if you want! Don't be shy!
      Frequently Asked Questions (FAQs) & Their answers
      Q #1. What are Arrays?
      A. An Array is an datatype of an variable (AutoIt has many datatypes of variables like "strings", "integers" etc. Array is one of them). An Array can store information in a orderly manner. An Array consist of elements, each element can be considered as a variable (and yes, each element has its own datatype!). AutoIt can handle 16,777,216 elements in an Array, If you have an Array with 16,777,217 elements then AutoIt crashes.
      Q #2. Help! I get an error while declaring an Array!?
      A. You tried to declare an array like this:
      $aArray[1] = ["Data"] That is not the right way, Array is a special datatype, since its elements can be considered as individual variables you must have an declarative keyword like Dim/Global/Local before the declaration, So this would work:
      Local $aArray[1] = ["Data"] Q #3. How can I calculate the no. of elements in an array?
      A. The UBound function is your answer, Its what exactly does! If you have an multi-dimensional Array you can calculate the total no. of elements in that dimension by specifying the dimension in the second parameter of UBound
      Q #4. Why is my For...Next loop throwing an error while processing an Array?
      A.  You might have done something like this:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) ; Concentrate here! $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Did you notice the mistake? UBound returns the no. of elements in an array with the index starting from 1! That's right, you need to remove 1 from the total no. of elements in order to process the array because the index of an array starts with 0! So append a simple - 1 to the statment:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) - 1 $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Q #5. Can an Array contain an Array? How do I access an Array within an Array?
      A. Yes! It is possible that an Array can contain another Array! Here is an example of an Array within an Array:
      ; An Array can contain another Array in one of its elements ; Let me show you an example of what I mean ;) #include <Array.au3> Global $aArray[2] $aArray[0] = "Foo" Global $aChildArray[1] = ["Bar"] $aArray[1] = $aChildArray _ArrayDisplay($aArray) ; Did you see that!? The 2nd element is an {Array} :O ; But how do we access it??? ; You almost guessed it, like this: ; Just envolope the element which contains the {Array} (as shown in _ArrayDisplay) with brackets (or parentheses)! :D ConsoleWrite(($aArray[1])[0]) ; NOTE the brackets () around $aArray[1]!!! They are required or you would get an syntax error! ; So this: $aArray[1][0] wont work!  
      More FAQs coming soon!
    • By jasty
      In every other language doing   
      dim $a[3] = [1, 2, 3] $b = $a creates a reference to a but in autoit it always makes a copy.  I didn't realize this until I have performance problems and now I'm trying to switch over to the reference behavior.  How can I change the above statement so b is a reference to a and not a full copy? 
    • By Emmhor1
      Hi All,

      MAIN QUESTION:
      Is it possible to Call specific function within a GUI

      So I have a script with multiple functions although I don't want to use every function every time.
      My Idea is to create a simple GUI which allows me to select what functions I want to use then run the funtions by clicking a button.
      I have already made a GUI which allows me to select specific .exe's I would like to run after selection it runs the .exe one by one.
      This script is on my work laptops and cannot access it right now.
       
      Who can help me with this?
      GUIcreate
      Func1 
      Func2
      Func3
      Then have a boxes which allows me to select the specif Func.(I used GUIChecked and Unchecked in my other script)
      Then a button which executes/calls the selected functions
×
×
  • Create New...