Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Array mind bender help

$
0
0

I'm in the middle of a rather large project, and have gotten to the point where I'm out of ideas on how to handle populating arrays and sorting them, from other arrays.

 

To me, it's quite complicated and I'm quite lousy with words, but I'll try just that same.

 

I have a 'Master' array, which has in it a lot of names of items.

Those items have 2 specific types, the type, and the subtype.

 

Into my script I get some arrays passed (determined at runtime)

 

I need to use the master array, by looping through it to determine how many of each item are listed in the passed in arrays, add up the total of all the sub types of each type, and show it in a new array. The sub types must also be listed under the type.

Like I say, it's quite complicated, and the passed in arrays may or may not contain a given type, or a certain subtype of that type.

 

I'm getting lost again here, so I'l post the reproduce I've made (I hoped I'd get insired while creating the reproducer, but alas, I did not)

 

Hope someone can make sense of it with comments, and offer some help...

AutoIt         
#include <Array.au3> ; Some Strings to create arrays from $sNames = "Name1,Name2,Name3,Name4,Name5,Name6,Name7,Name8,Name9,Name10,Name11," _          & "TName12,Name13,Name14,Name15,Name16,Name17,Name18,Name19,Name20,Name21," _          & "Name22,Name23,Name24,Name25,Name26,Name27,Name28,Name29,Name30,Name31," _          & "Name32,Name33,Name34,Name35,Name36,Name37,Name38,Name39,Name40" $sTypes = "Type1,Type2,Type3,Type4,Type5" $sSubTypes = "SubType1,SubType2,SubType3,SubType4,SubType5,SubType6,SubType7," _          & "SubType8,SubType9,SubType10,SubType11,SubType12,SubType13,SubType14,SubType15" ; Create arrays for Item Names, Item Types, and Item Sub Types Global $aNames = StringSplit($sNames, ",", 2) Global $aTypes = StringSplit($sTypes, ",", 2) Global $aSubTypes = StringSplit($sSubTypes, ",", 2) ; Create a 2D array With all Names, and fill it ; they must have a randon type nnd sub type Global $aMasterArray[UBound($aNames)][3] For $i = 0 To UBound($aNames) - 1     $aMasterArray[$i][0] = $aNames[$i]     $aMasterArray[$i][1] = $aTypes[Random(0, UBound($aTypes) - 1, 1)]     $aMasterArray[$i][2] = $aSubTypes[Random(0, UBound($aSubTypes) - 1, 1)] Next ; So this is the master array, similar to what I'm working with _ArrayDisplay($aMasterArray, "$aMasterArray") ; Now here I'm generating an array of sub arrays, which gets fed into ; my script via some other methods. ; ; I do not know how many sub arrays there will be until run time ; which is why I have to hold them in a dynamic array. Global $ArrayOfArrays = _GenerateArrayOfArrays() _ArrayDisplay($ArrayOfArrays, "$ArrayOfArrays") ; This is what I'd likr the resulting array to be like _Wish() Func _GenerateArrayOfArrays()     ; Array needs to hold a random amount of sub arrays     Local $iNumberOfSubArrays = Random(2, 7, 1)     ; Create array with random index count     ; plus 1 to hold the count     Local $aArrays[$iNumberOfSubArrays + 1] = [$iNumberOfSubArrays]     ; Add sub arrays to $aArrays     For $i = 1 To Int($aArrays[0])         $aArrays[$i] = _GenerateArray()     Next     Return $aArrays EndFunc   ;==>_GenerateArrayOfArrays Func _GenerateArray()     ; Sub arrays also need random index count     ; They have random Name, Type, and Sub Type same as master array     ; except they also have a value in col 3     Local $iIndexCount = Random(10, 60, 1)     Local $array[$iIndexCount][4]     For $i = 0 To UBound($array) - 1         $array[$i][0] = $aNames[Random(0, UBound($aNames) - 1, 1)]         $array[$i][1] = $aTypes[Random(0, UBound($aTypes) - 1, 1)]         $array[$i][2] = $aSubTypes[Random(0, UBound($aSubTypes) - 1, 1)]         $array[$i][3] = Round(Random(0, 200), 2)     Next     _ArraySort($array)     _ArrayDisplay($array, "Sub array")     Return $array EndFunc   ;==>_GenerateArray Func _Wish()     Local $array[10][7]     $array[0][0] = "Type1"     $array[0][1] = "283.56"     $array[0][2] = "413.56"     $array[0][3] = "52.06"     $array[0][4] = "320.51"     $array[0][5] = "763.36"     $array[0][6] = "685.00"     $array[1][0] = "SubType1"     $array[1][1] = "29.56"     $array[1][2] = "63.56"     $array[1][3] = "2.06"     $array[1][4] = "90.51"     $array[1][5] = "64.36"     $array[1][6] = "15.00"     $array[2][0] = "SubType2"     $array[2][1] = "29.56"     $array[2][2] = "63.56"     $array[2][3] = "2.06"     $array[2][4] = "90.51"     $array[2][5] = "64.36"     $array[2][6] = "15.00"     $array[3][0] = "SubType4"     $array[3][1] = "29.56"     $array[3][2] = "63.56"     $array[3][3] = "2.06"     $array[3][4] = "90.51"     $array[3][5] = "64.36"     $array[3][6] = "15.00"     $array[4][0] = "Type2"     $array[4][1] = "283.56"     $array[4][2] = "413.56"     $array[4][3] = "52.06"     $array[4][4] = "320.51"     $array[4][5] = "763.36"     $array[4][6] = "685.00"     $array[5][0] = "SubType3"     $array[5][1] = "83.56"     $array[5][2] = "13.56"     $array[5][3] = "2.06"     $array[5][4] = "20.51"     $array[5][5] = "63.36"     $array[5][6] = "85.00"     $array[6][0] = "SubType6"     $array[6][1] = "83.56"     $array[6][2] = "13.56"     $array[6][3] = "2.06"     $array[6][4] = "20.51"     $array[6][5] = "63.36"     $array[6][6] = "85.00"     $array[7][0] = "Type3"     $array[7][1] = "283.56"     $array[7][2] = "413.56"     $array[7][3] = "52.06"     $array[7][4] = "320.51"     $array[7][5] = "763.36"     $array[7][6] = "685.00"     $array[8][0] = "SubType5"     $array[8][1] = "83.56"     $array[8][2] = "13.56"     $array[8][3] = "2.06"     $array[8][4] = "20.51"     $array[8][5] = "63.36"     $array[8][6] = "85.00"     $array[9][0] = "SubType8"     $array[9][1] = "83.56"     $array[9][2] = "13.56"     $array[9][3] = "2.06"     $array[9][4] = "20.51"     $array[9][5] = "63.36"     $array[9][6] = "85.00"     _ArrayDisplay($array, "Type then all it's subtypes below, the large number = sum of sub types") EndFunc   ;==>_Wish

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>