Jump to content

Why can't you put an array into a function?


Recommended Posts

Can anyone tell me why you can't input an array into a function like this? 

This hits the error check 

_IEFormElementOptionSelect($BusinessSectorCodeID,$BusinessSectorCodeDropdownArray[1])

If @Error Then
   ConsoleWrite(@CRLF & "Error setting dropdown for business sector Code: " & $BusinessSectorCodeDropdownArray[1])
exit
   Endif

however this doesn't 

_IEFormElementOptionSelect($BusinessSectorCodeID,"test code")

If @Error Then
   ConsoleWrite(@CRLF & "Error setting dropdown for business sector Code: " & $BusinessSectorCodeDropdownArray[1])
exit
   Endif

 

Edited by CaptainBeardsEyesBeard
Link to comment
Share on other sites

Oh sorry I forgot to show you my declaration of the array  

Local $BusinessSectorFullDropdownArray[72] ; Make room for three elements
 ;Assign some data
$file = "H:\Quality Assurance\AutoIT Scripts\EliteClientInceptionAutomation\TestData\BusinessSectorCodeDropdown.txt"
FileOpen($file, 0)
Global $arr[72]
For $i = 1 to _FileCountLines($file)
    $line = FileReadLine($file, $i)
    ReDim $arr[_FileCountLines($file)+1]
    $arr[$i] = $line
Next

MsgBox(64, "Test Log", "Dropdown is : "  & $BusinessSectorCodeDropdownArray[1])

_IEFormElementOptionSelect($BusinessSectorCodeID,$BusinessSectorCodeDropdownArray[1])

When I do the above when it hits the message box it the message is only "Dropdown is : " with no variable in there 

 

However if I do an array display it displays all of the variables in the text file (screenshot of top one) 

_ArrayDisplay($arr, "1D display")

1.png.4efe727ac97ee05264e9392190b6a382.png

Link to comment
Share on other sites

You could also just use _FileReadToArray to get your array:

#include <Array.au3>
#include <File.au3>
Local $sFileName = @ScriptDir & "\Data.txt"
Local $aBusinessSectorCodeDropdown
    _FileReadToArray($sFileName, $aBusinessSectorCodeDropdown, 1)
        If @error Then Exit MsgBox(4096, "Error", "Error reading file to array.")
_IEFormElementOptionSelect($BusinessSectorCodeID,$aBusinessSectorCodeDropdownArray[1])

 

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...