Der_Andi Posted August 14, 2007 Share Posted August 14, 2007 Hi,i'm working with a 2dim-Array, that has 10 rows and 5 columns.But not every row has all 5 columns filled with an item.Dim $aKrit[10][5] = [ _ ["PVO", "A", "B", "C"], _ ["Sourcing Situation", "single", "double", "multi"], _ ["Potential (Capacity)", "Flexibility", "+- 5%", "+- 10%", "+-25%"], _ ["Potential (technical)", "standard", "development partner"], _ ["Product Complex", "inhouse", "external"], _ ["Contract Status", "none", "NDA", "PUC, Gen. Tec. Spec", "QAA"], _ ["Social aspects", "official statement", "none"], _ ["Environm. compliance", "ISO 14001", "none"], _ ["Certification level", "ISO TS", "ISO 9001", "none"], _ ["Avail. of QM-Tools", "8D, FMEA, Control Plan", "partly", "none"] ]How can i get the actual count of items in a specific row?"PVO"-Line would be 4, "Product Complex"-Line would be 3, etc...Is there a special function available, or do i have to try item by item until an error occurs?Andi Link to comment Share on other sites More sharing options...
Kip Posted August 14, 2007 Share Posted August 14, 2007 UBound($aKrit,2) MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 14, 2007 Share Posted August 14, 2007 Hi, i'm working with a 2dim-Array, that has 10 rows and 5 columns. But not every row has all 5 columns filled with an item. How can i get the actual count of items in a specific row? "PVO"-Line would be 4, "Product Complex"-Line would be 3, etc... Is there a special function available, or do i have to try item by item until an error occurs? Andi Like this: Dim $aKrit[10][5] = [ _ ["PVO", "A", "B", "C"], _ ["Sourcing Situation", "single", "double", "multi"], _ ["Potential (Capacity)", "Flexibility", "+- 5%", "+- 10%", "+-25%"], _ ["Potential (technical)", "standard", "development partner"], _ ["Product Complex", "inhouse", "external"], _ ["Contract Status", "none", "NDA", "PUC, Gen. Tec. Spec", "QAA"], _ ["Social aspects", "official statement", "none"], _ ["Environm. compliance", "ISO 14001", "none"], _ ["Certification level", "ISO TS", "ISO 9001", "none"], _ ["Avail. of QM-Tools", "8D, FMEA, Control Plan", "partly", "none"] ] $ColUsed = _ArrayGetUsedColCnt($aKrit, 4) If Not @error Then MsgBox(64, "Results", "There are " & $ColUsed & " rows where column 4 is not null.") Else MsgBox(16, "Error", "Error! _ArrayGetUseColCnt() returned: " & $ColUsed & ", @error = " & @error) EndIf Func _ArrayGetUsedColCnt(ByRef $avInput, $iCol = 0, $iStart = 0) If Not IsArray($avInput) Then Return SetError(1, 0, -1) If $iCol > UBound($avInput, 2) - 1 Then Return SetError(2, 0, -1) If $iStart > UBound($avInput) - 1 Then Return SetError(3, 0, -1) Local $RET = 0 For $n = $iStart To UBound($avInput) - 1 If $avInput[$n][$iCol] <> "" Then $RET += 1 Next Return $RET EndFunc ;==>_ArrayGetUsedColCnt Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 14, 2007 Share Posted August 14, 2007 Use two For loops to check if the values of the array are greater than null. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
weaponx Posted August 14, 2007 Share Posted August 14, 2007 Use two For loops to check if the values of the array are greater than null. Checking for nulls in an array is a bad idea, especially with multiple dimensions. Counting until null in the array below based on the 3rd column would only return 2 items. [Ford, Red, 4-Door] [Chevy, Black, 2-Door] [Nissan, White] [Dodge, Black, 2-Door] Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 14, 2007 Share Posted August 14, 2007 Checking for nulls in an array is a bad idea, especially with multiple dimensions. Counting until null in the array below based on the 3rd column would only return 2 items. [Ford, Red, 4-Door] [Chevy, Black, 2-Door] [Nissan, White] [Dodge, Black, 2-Door] The function I posted counts ALL rows in the selected column that are not null. Here is it with your data: Dim $aTrucks[4][3] = [['Ford', 'Red', '4-Door'], ['Chevy', 'Black', '2-Door'], _ ['Nissan', 'White'], ['Dodge', 'Black', '2-Door']] $ColUsed = _ArrayGetUsedColCnt($aTrucks, 2) If Not @error Then MsgBox(64, "Results", "There are " & $ColUsed & " rows where column 2 is not null.") Else MsgBox(16, "Error", "Error! _ArrayGetUseColCnt() returned: " & $ColUsed & ", @error = " & @error) EndIf Func _ArrayGetUsedColCnt(ByRef $avInput, $iCol = 0, $iStart = 0) If Not IsArray($avInput) Then Return SetError(1, 0, -1) If $iCol > UBound($avInput, 2) - 1 Then Return SetError(2, 0, -1) If $iStart > UBound($avInput) - 1 Then Return SetError(3, 0, -1) Local $RET = 0 For $n = $iStart To UBound($avInput) - 1 If $avInput[$n][$iCol] <> "" Then $RET += 1 Next Return $RET EndFunc ;==>_ArrayGetUsedColCntoÝ÷ ØéÞ(!·¬Ú©àzØZ¶×¬¶Ú-çèZ0x,¢ØZµé©·,!׬¥§Ëky«^u«'ºYZºÚ"µÍÜ ÌÍÛH ÌÍÚTÝÈPÝ[ ÌÍØ][] HHBYÝ[ÔÝÔÊ ÌÍØ][]ÉÌÍÛVÉÌÍÚPÛÛK H ÉÝÈ ][ÝÉ][ÝÈ[ ÌÍÔU ÏHB^ Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Der_Andi Posted August 14, 2007 Author Share Posted August 14, 2007 Like this: Func _ArrayGetUsedColCnt(ByRef $avInput, $iCol = 0, $iStart = 0) If Not IsArray($avInput) Then Return SetError(1, 0, -1) If $iCol > UBound($avInput, 2) - 1 Then Return SetError(2, 0, -1) If $iStart > UBound($avInput) - 1 Then Return SetError(3, 0, -1) Local $RET = 0 For $n = $iStart To UBound($avInput) - 1 If $avInput[$n][$iCol] <> "" Then $RET += 1 Next Return $RET EndFunc ;==>_ArrayGetUsedColCnt Like this! But you go through all rows with a FIX col-index. I need it the other way around. Anyway, it helped. Thanks. Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 14, 2007 Share Posted August 14, 2007 Like this! But you go through all rows with a FIX col-index. I need it the other way around. Anyway, it helped. Thanks. Ooh. I see what you meant now. That explains why mikehunt said to use two nested loops. This works that way, I think: #include <array.au3> ; for _ArrayDisplay() Dim $aKrit[10][5] = [ _ ["PVO", "A", "B", "C"], _ ["Sourcing Situation", "single", "double", "multi"], _ ["Potential (Capacity)", "Flexibility", "+- 5%", "+- 10%", "+-25%"], _ ["Potential (technical)", "standard", "development partner"], _ ["Product Complex", "inhouse", "external"], _ ["Contract Status", "none", "NDA", "PUC, Gen. Tec. Spec", "QAA"], _ ["Social aspects", "official statement", "none"], _ ["Environm. compliance", "ISO 14001", "none"], _ ["Certification level", "ISO TS", "ISO 9001", "none"], _ ["Avail. of QM-Tools", "8D, FMEA, Control Plan", "partly", "none"] ] $ColUsed = _ArrayRowsGetColUsed($aKrit) If Not @error Then _ArrayDisplay($ColUsed, "Columns used in each row") Else MsgBox(16, "Error", "Error! _ArrayRowsGetColUsed() returned: " & $ColUsed & ", @error = " & @error) EndIf ; Returns an array with the number of non-null columns in each row Func _ArrayRowsGetColUsed(ByRef $avInput) If Not IsArray($avInput) Then Return SetError(1, 0, -1) Local $avRET[UBound($avInput) ] For $r = 0 To UBound($avInput) - 1 $avRET[$r] = 0 For $c = 0 To UBound($avInput, 2) - 1 If StringStripWS($avInput[$r][$c], 8) <> "" Then $avRET[$r] += 1 Next Next Return $avRET EndFunc ;==>_ArrayRowsGetColUsed Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 14, 2007 Share Posted August 14, 2007 (edited) Checking for nulls in an array is a bad idea, especially with multiple dimensions. Counting until null in the array below based on the 3rd column would only return 2 items. [Ford, Red, 4-Door] [Chevy, Black, 2-Door] [Nissan, White] [Dodge, Black, 2-Door] Only if you exit the loop. If my post came across like that, it was not intended. Simply log as you go. Edit: To be clear: #include <Array.au3> Dim $aTest[4][3] = [["Ford", "Red", "4-Door"], _ ["Chevy", "Black", "2-Door"], _ ["Nissan", "White"], _ ["Dodge", "Black", "2-Door"]] $nullCount = 0 For $i = 0 To UBound($aTest) - 1 For $j = 0 To UBound($aTest, 2) - 1 If String($aTest[$i][$j]) = "" Then $nullCount += 1 Next Next MsgBox(0, "", "Null elements: " & $nullCount) You can make different comparisons in the If statement, to include or disclude things like just whitespaces, as PSalty mentioned. Edited August 14, 2007 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now