Jump to content

Another question about dealing with Array


Recommended Posts

Hi folks.

I have some trouble with writing Array to an Variable.

Here is the code:

#include <Array.au3>

; Create an 2D-Array
Local $TV_1[11][2] = [["TV1", 0], ["TV2", 1], ["TV3", 0], ["TV4", 1], ["TV5", 0], ["TV6", 1], ["TV7", 0], ["TV8", 1], ["TV9", 0], ["TV10", 1], ["TV11", 0]]
_ArrayDisplay($TV_1, "2D Array")

; Now search vor " 0 " in Sub-Index 1 of above 2D-Array. Columns only
Local $aiResult = _ArrayFindAll($TV_1, 0, Default, Default, Default, Default, 1, False)
_ArrayDisplay($aiResult, "Result")
; Ok. The "0" was found on positions: 0, 2, 4, 6, 8, 10.
; So far so good

; Now i check the dimension of the array. It should be max. 6!
If Ubound($aiResult) = 6 Then

; And here i stuck. I want to "write" the found positions(0, 2, 4, 6, 8, 10) position by position to an variable like $TV and transfer it to a function.
   For ???? To ????
      _Example($TV)
   Next
EndIf

Func _Example($TV)
   If $TV = 0 Then ConsoleWrite("TV1" & @CRLF)
   If $TV = 1 Then ConsoleWrite("TV2" & @CRLF)
   If $TV = 2 Then ConsoleWrite("TV3" & @CRLF)
   If $TV = 3 Then ConsoleWrite("TV4" & @CRLF)
   If $TV = 4 Then ConsoleWrite("TV5" & @CRLF)
   If $TV = 5 Then ConsoleWrite("TV6" & @CRLF)
   If $TV = 6 Then ConsoleWrite("TV7" & @CRLF)
   If $TV = 7 Then ConsoleWrite("TV8" & @CRLF)
   If $TV = 8 Then ConsoleWrite("TV9" & @CRLF)
   If $TV = 9 Then ConsoleWrite("TV10" & @CRLF)
   If $TV = 10 Then ConsoleWrite("TV11" & @CRLF)
EndFunc

Many thx in advance.

Edited by P0LarWolF
Link to comment
Share on other sites

Did you have a look at the help file to see how "For...In...Next" works?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The example provided in the help file shows how to process an array.
So your script should look like:

For $iNumber In $aiResult
    _Example($iNumber)
Next

or

For $iNumber = 0 To UBound($aiResult) - 1
    _Example($iNumber)
Next

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

NB: Shouldn't this line

; Now i check the dimension of the array. It should be max. 6!
If Ubound($aiResult) = 6 Then

be

; Now i check the dimension of the array. It should be max. 6!
If Ubound($aiResult) <= 6 Then

Because "max. 6" means 6 or lower to me ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Good morning.

Is there a easy way to update all the values inside my 2-D Array. I mean only the values in index 1 ( all the zeros).

#include <Array.au3>

; Create an 2D-Array
Local $TV_Array[11][2] = [["TV1", 0], ["TV2", 0], ["TV3", 0], ["TV4", 0], ["TV5", 0], ["TV6", 0], ["TV7", 0], ["TV8", 0], ["TV9", 0], ["TV10", 0], ["TV11", 0]]
_ArrayDisplay($TV_Array, "2D Array")

; Now search vor " 0 " in Sub-Index 1 of above 2D-Array. Columns only
Local $aiResult = _ArrayFindAll($TV_Array, 0, Default, Default, Default, Default, 1, False)
_ArrayDisplay($aiResult, "Result")
; Ok. The "0" was found on positions: 0, 2, 4, 6, 8, 10.
; So far so good

; Now i check the dimension of the array. It should be exactly 6!
If Ubound($aiResult) = 6 Then

; Write the found positions(0, 2, 4, 6, 8, 10) position by position to an variable $TV and transfer function _Example().
   For $TV in $aiResult
   _Example($TV)
   Next
EndIf

Func _Example($TV)
   If $TV = 0 Then ConsoleWrite("TV1" & @CRLF)
   If $TV = 1 Then ConsoleWrite("TV2" & @CRLF)
   If $TV = 2 Then ConsoleWrite("TV3" & @CRLF)
   If $TV = 3 Then ConsoleWrite("TV4" & @CRLF)
   If $TV = 4 Then ConsoleWrite("TV5" & @CRLF)
   If $TV = 5 Then ConsoleWrite("TV6" & @CRLF)
   If $TV = 6 Then ConsoleWrite("TV7" & @CRLF)
   If $TV = 7 Then ConsoleWrite("TV8" & @CRLF)
   If $TV = 8 Then ConsoleWrite("TV9" & @CRLF)
   If $TV = 9 Then ConsoleWrite("TV10" & @CRLF)
   If $TV = 10 Then ConsoleWrite("TV11" & @CRLF)
EndFunc

I tried nested for/next loops like this, but this function updates both indexes.

#Include <Array.au3>

Local $a[2][2] = [[0,1],[10,20]]

For $i = 0 to UBound($a)-1
    For $j = 0 to UBound($a, 2)-1
        $a[$i][$j] += 5
    Next
Next
_ArrayDisplay($a)

thx in davance

Edited by P0LarWolF
Link to comment
Share on other sites

Then call the other function and assing the return value to your array.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hi. Here is my solution for the moment. What do you think?

Func _ReDimArray()
   Local $i = 0
   ReDim $TV_Array[$i + 11][2]
    $TV_Array[$i][1] = 11
    $i += 1
    $TV_Array[$i][1] = 12
    $i += 1
    $TV_Array[$i][1] = 13
    $i += 1
    $TV_Array[$i][1] = 14
    $i += 1
    $TV_Array[$i][1] = 15
    $i += 1
    $TV_Array[$i][1] = 16
    $i += 1
    $TV_Array[$i][1] = 17
    $i += 1
    $TV_Array[$i][1] = 18
    $i += 1
    $TV_Array[$i][1] = 19
    $i += 1
    $TV_Array[$i][1] = 20
    $i += 1
    $TV_Array[$i][1] = 21
    $i += 1
    _ArrayDisplay($TV_Array, "2D Array")
EndFunc

This way also work

For $i = 0 To UBound($TV_Array) - 1
   If $i = 0 Then
       $TV_Array[$i][1] = 4
   Elseif $i = 1 Then
       $TV_Array[$i][1] = 100
   EndIf
   ; and so on
Next
_ArrayDisplay($TV_Array, "2D Array")

I think the fist solution is ab bit shorter, withot If...ElseIf..Then

Link to comment
Share on other sites

What is your goal? Do you want to call the function to extend the array by 11 rows and initialize the second columns with $i + 11?
So after the first call the array would have 11 rows, after the second call 22 and so on.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The Array should have always 11 rows. I just want to update every value row by row in column 1. Values(in my case strings) in column 0 are always the same

That's the starting Array

Global $TV_Array[11][2] = [["TV1", 0], ["TV2", 1], ["TV3", 1], ["TV4", 0], ["TV5", 0], ["TV6", 1], ["TV7", 0], ["TV8", 1], ["TV9", 0], ["TV10", 1], ["TV11", 0]]

 

Edited by P0LarWolF
Link to comment
Share on other sites

Something like this.

#include <Array.au3>

Global $aTV_Array[11][2] = [["TV1", 0], ["TV2", 0], ["TV3", 0], ["TV4", 0], ["TV5", 0], ["TV6", 0], ["TV7", 0], ["TV8", 0], ["TV9", 0], ["TV10", 0], ["TV11", 0]]
_ArrayDisplay($aTV_Array)
InitArray($aTV_Array)
_ArrayDisplay($aTV_Array)

Func InitArray(ByRef $aArray)
    Local $iOffset = 11
    For $i = 0 To UBound($aArray, 1) - 1
        $aArray[$i][1] = $i + $iOffset
    Next
EndFunc   ;==>InitArray

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...