Sign in to follow this  
Followers 0
cookiemonster

Calling data from 2D Array

5 posts in this topic

#1 ·  Posted (edited)

Right this is my first time using arrays, I have created a 2D array

#include <Array.au3>

Local $a2DArray[3][2] = [ _
['text1', 'answer1'], _
['text2', 'answer2'], _
['text1', 'answer2']]

_ArrayDisplay($a2DArray, "2D display") ;

What I was to do is pull out the data from row 0 column 0 to a variable $loc and data from row 0 column 1 to variable $ans

Then run that through a function like:

Func check()
local $Aloc = $loc
local $Aans = $ans

If $Aloc = "text1" & $Aans = "answer1" then
   msgbox(4096,"Success","Answer was test1")
Else
   msgbox(4096,"Fail","Answer Failed Check"
Endif

EndFunc ;==>check

then it needs to do it all again for the next row and so on

Can anyone point me in the right direction?

Edited by cookiemonster

Share this post


Link to post
Share on other sites



For $iIndex = 0 to UBound(a2DArray, 1) - 1
    check($a2DArray[$iIndex][0], $a2DArray[$iIndex][1])
Next

Func check($Aloc, $Aans)

    If $Aloc = "text1" & $Aans = "answer1" then
       msgbox(4096,"Success","Answer was test1")
    Else
       msgbox(4096,"Fail","Answer Failed Check")
    Endif

EndFunc ;==>chec


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I have tried that so the total script is:

#include <Array.au3>

Local $a2DArray[3][2] = [ _
['text1', 'answer1'], _
['text2', 'answer2'], _
['text1', 'answer2']]

_ArrayDisplay($a2DArray, "2D display") ; 

For $iIndex = 0 to UBound($a2DArray, 1) - 1
    check($a2DArray[$iIndex][0], $a2DArray[$iIndex][1])
Next

Func check($Aloc, $Aans)

    If $Aloc = "text1" & $Aans = "answer1" then
       msgbox(4096,"Success","Answer was test1")
    Else
       msgbox(4096,"Fail","Answer Failed Check")
    Endif

EndFunc ;==>chec

However the first row of the array should come back with the message box "Success" "Answer was test1" but it doesnt, it comes back with the fail message box, any ideas?

Share this post


Link to post
Share on other sites

I cant understand why what Water wrote isnt working but ive implemented parts into my script and it works fine...

Share this post


Link to post
Share on other sites

& is not a substitute for the keyword And ;)

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
Sign in to follow this  
Followers 0