Jump to content

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded site


Go to solution Solved by ioa747,

Recommended Posts

Posted (edited)

 

I'm getting the Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded site for the below code. I have integrated AutoIt with Selenium. While compiling the script I'm not getting any error but while running the script I'm getting this error. Please help. 

 

AutoIt code:

#include <ScreenCapture.au3>
$option = $CmdLine[4]
$filepath = $CmdLine[1]
$sspath =$CmdLine[2]
$sspath2 = $CmdLine[3]
ControlFocus("Select Folder to Upload","","Edit1")
if $option = "screenshot" Then
    popupIsDisplayed()
ElseIf $option = "cancel" Then
    clickCancelInPopUp()
ElseIf $option = "select file" Then
    selectFile()
    clickUploadInPopUp()
ElseIf $option = "alert screenshot" Then
    alertISDisplayed()
ElseIf $option = "upload" Then
    clickUploadInAlert()
ElseIf $option = "cancel alert" Then
    clickCancelInAlert()
EndIf
Exit


Func popupIsDisplayed()
    ControlFocus("Select Folder to Upload","","Edit1")
    Sleep(2000)
    Example()
EndFunc

Func clickCancelInPopUp()
    ControlClick("Select Folder to Upload","","Button2")
EndFunc

Func selectFile()
    ControlSetText("Select Folder to Upload","","Edit1", $filepath)
    Sleep(2000)
    Example()
    Sleep(2000)
EndFunc

Func clickUploadInPopUp()
    ControlClick("Select Folder to Upload","","Button1")
    Sleep(2000)
EndFunc

Func alertISDisplayed()
    Example2()
EndFunc

Func clickUploadInAlert()
    Example2()
    Send("{Tab}")
    Send("{Enter}")
EndFunc

Func clickCancelInAlert()
    Example2()
    Send("{Enter}")
EndFunc

Func Example()
        Local $hBmp

        ; Capture full screen
        $hBmp = _ScreenCapture_Capture("")

        ; Save bitmap to file
        _ScreenCapture_SaveImage($sspath, $hBmp)
EndFunc   ;==>Example

    Func Example2()
        Local $hBmp

        ; Capture full screen
        $hBmp = _ScreenCapture_Capture("")

        ; Save bitmap to file
        _ScreenCapture_SaveImage($sspath2, $hBmp)
EndFunc   ;==>Example

 

 

Java Code:

String autoItScriptPath = System.getProperty("user.dir") + "\\src\\test\\resources\\autoit\\FileUpload.exe";

public void uploadFile(String folderName) throws IOException, InterruptedException {
        String folderPath = System.getProperty("user.dir") + "\\src\\test\\resources\\datasets\\"+folderName;
        String SSPath = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "1",
                LoginPage.driver);
        String[] cmd = { autoItScriptPath, folderPath, SSPath, "","select file" };
        Runtime.getRuntime().exec(cmd);
        Thread.sleep(5000);
    }



public void alertIsDisplayed() throws IOException, InterruptedException {
        String SSPath = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "1",
                LoginPage.driver);
        String[] cmd = { autoItScriptPath, "", SSPath, "", "alert screenshot" };
        Runtime.getRuntime().exec(cmd);
        Thread.sleep(3000);
    }

    public static String uploadTime = null;

public void clickUploadInAlert() throws IOException, InterruptedException {
        String SSPath2 = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "2",
                LoginPage.driver);
        String[] cmd = { autoItScriptPath, "", "", SSPath2, "upload" };
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a");  
        LocalDateTime now = LocalDateTime.now();  
        Runtime.getRuntime().exec(cmd);
        Thread.sleep(3000);
        uploadTime = dtf.format(now);
        logger.info("uploadTime: " +uploadTime);
    }


      

 

Edited by Jos
added codeboxes
Posted

Check that $CmdLine actually contains the stuff you pass to AutoIt using

_ArrayDisplay($CmdLine)

You are somehow accessing an array element that doesn't exist.

Use Ubound($CmdLine) to check the size of the array and handle error cases.

Posted
Just now, SatheshVp said:

@pawI'm not getting you, where should I update the code. 

 

20 minutes ago, SatheshVp said:

 

I'm getting the Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded site for the below code. I have integrated AutoIt with Selenium. While compiling the script I'm not getting any error but while running the script I'm getting this error. Please help. 

 

AutoIt code:

#include <ScreenCapture.au3>
$option = $CmdLine[4]
$filepath = $CmdLine[1]
$sspath =$CmdLine[2]
$sspath2 = $CmdLine[3]
ControlFocus("Select Folder to Upload","","Edit1")
if $option = "screenshot" Then
    popupIsDisplayed()
ElseIf $option = "cancel" Then
    clickCancelInPopUp()
ElseIf $option = "select file" Then
    selectFile()
    clickUploadInPopUp()
ElseIf $option = "alert screenshot" Then
    alertISDisplayed()
ElseIf $option = "upload" Then
    clickUploadInAlert()
ElseIf $option = "cancel alert" Then
    clickCancelInAlert()
EndIf
Exit


Func popupIsDisplayed()
    ControlFocus("Select Folder to Upload","","Edit1")
    Sleep(2000)
    Example()
EndFunc

Func clickCancelInPopUp()
    ControlClick("Select Folder to Upload","","Button2")
EndFunc

Func selectFile()
    ControlSetText("Select Folder to Upload","","Edit1", $filepath)
    Sleep(2000)
    Example()
    Sleep(2000)
EndFunc

Func clickUploadInPopUp()
    ControlClick("Select Folder to Upload","","Button1")
    Sleep(2000)
EndFunc

Func alertISDisplayed()
    Example2()
EndFunc

Func clickUploadInAlert()
    Example2()
    Send("{Tab}")
    Send("{Enter}")
EndFunc

Func clickCancelInAlert()
    Example2()
    Send("{Enter}")
EndFunc

Func Example()
        Local $hBmp

        ; Capture full screen
        $hBmp = _ScreenCapture_Capture("")

        ; Save bitmap to file
        _ScreenCapture_SaveImage($sspath, $hBmp)
EndFunc   ;==>Example

    Func Example2()
        Local $hBmp

        ; Capture full screen
        $hBmp = _ScreenCapture_Capture("")

        ; Save bitmap to file
        _ScreenCapture_SaveImage($sspath2, $hBmp)
EndFunc   ;==>Example

 

 

Java Code:

String autoItScriptPath = System.getProperty("user.dir") + "\\src\\test\\resources\\autoit\\FileUpload.exe";

public void uploadFile(String folderName) throws IOException, InterruptedException {
        String folderPath = System.getProperty("user.dir") + "\\src\\test\\resources\\datasets\\"+folderName;
        String SSPath = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "1",
                LoginPage.driver);
        String[] cmd = { autoItScriptPath, folderPath, SSPath, "","select file" };
        Runtime.getRuntime().exec(cmd);
        Thread.sleep(5000);
    }

 

public void alertIsDisplayed() throws IOException, InterruptedException {
        String SSPath = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "1",
                LoginPage.driver);
        String[] cmd = { autoItScriptPath, "", SSPath, "", "alert screenshot" };
        Runtime.getRuntime().exec(cmd);
        Thread.sleep(3000);
    }

    public static String uploadTime = null;

public void clickUploadInAlert() throws IOException, InterruptedException {
        String SSPath2 = screenshot.autoITScreenshot(new Throwable().getStackTrace()[0].getMethodName() + "2",
                LoginPage.driver);
        String[] cmd = { autoItScriptPath, "", "", SSPath2, "upload" };
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a");  
        LocalDateTime now = LocalDateTime.now();  
        Runtime.getRuntime().exec(cmd);
        Thread.sleep(3000);
        uploadTime = dtf.format(now);
        logger.info("uploadTime: " +uploadTime);
    }
      

 

@Jos

  • Developers
Posted (edited)

@SatheshVp

What about you slow down a bit and stop begging/pinging people for support? This is considered very impolite and puts people off!
Who made this code for you, as you seems to be lost?


 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

@Jos Apologies for the discomfort. I didn't write this AutoIt code. It was written by some other person who is currently not in my company now. I'm new to the company and I don't see any person who has AutoIt knowledge in my project. 

Could you please help resolving this bug if you get time?

 

  • Developers
Posted

Guess you have some studying to do then! ;) 
You didn't specify, but the guess is you get the error on one of these:

$option = $CmdLine[4]
$filepath = $CmdLine[1]
$sspath =$CmdLine[2]
$sspath2 = $CmdLine[3]

Which is because you started the script without (enough) parameters and the coder has forgotten to test for that!
So open the AutoIt3 helpfile and look at the Running Scripts topic. 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

@JosI have gone through the Running Scripts topic. I'm still having confusion. 

I'm passing the array values in this array   String[] cmd = { autoItScriptPath, folderPath, SSPath, "","select file" };   to AutoIt

$CmdLine[1] is folder path

$CmdLine[2] is SSPath

$CmdLine[3] is null

$CmdLine[4]  is "select file"

$CmdLine[0] is "\\src\\test\\resources\\autoit\\FileUpload.exe"  [AutoIt .exe path]

But $CmdLine[0] means total number of items in the array in AutoIt. 

How to tackle this one?

 

  • Developers
Posted

Add these 3 lines at the top of your script:

#include <Array.au3>
_ArrayDisplay($CmdLine)
Exit

 ..compile it and run it again.  It should show the full $CmdLine array in a popup so you can see what is happening.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

@JosThanks, I found where the issue is. Array in AutoIt is not considering null value(""). 

 

Actual:

$CmdLine[0] = number of items

$CmdLine[1] = folder path

$CmdLine[2] = SSPath

$CmdLine[3] ="select file"

 

Expected:

$CmdLine[0] = number of items

$CmdLine[1] = folder path

$CmdLine[2] = SSPath

$CmdLine[3] = ""

$CmdLine[4] ="select file"

 

How can we pass null value ("")?

Posted (edited)

Just pass a dummy parameter, like "NULL" or specific character like "*".  Anything beside nothing....

ps. In java you need to escape quotation marks if you want to send them, this would be a valid parameter "\"\"" and it would be interpreted as Null value in AutoIt (like suggested by @argumentum below)

Edited by Nine
Posted (edited)
2 hours ago, SatheshVp said:

How can we pass null value ("")?

just do it.

For $n = 1 To $CmdLine[0]
    ConsoleWrite($n & @TAB & '>' & $CmdLine[$n] & '<' & @CRLF)
Next
Exit

I passed 1 "" 3 4 and got

1   >1<
2   ><
3   >3<
4   >4<

so yes you can.


What I would do in your case is

Global $option, $filepath, $sspath, $sspath2
If $CmdLine[0] > 3 Then $option = $CmdLine[4]
If $CmdLine[0] > 0 Then $filepath = $CmdLine[1]
If $CmdLine[0] > 1 Then $sspath =$CmdLine[2]
If $CmdLine[0] > 2 Then $sspath2 = $CmdLine[3]

so you don't get the error you got with your code.
 

Then again, you'll have to learn to think and explore on your own. My 2 cents even if you don't like it

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • Solution
Posted

my approach

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <ScreenCapture.au3>

Global $aArgs = $CmdLine
;~ Global $aArgs = [5, "one", 2, "three", "", "five"] ;test

Global $filepath, $sspath, $sspath2, $option

If $aArgs[0] = 4 Then
    $aArgs[0] = "CallArgArray"
    Call("_main", $aArgs)
Else
    Global $sMsg = "Number of parameters: " & $aArgs[0] & @CRLF
    For $i = 1 To $aArgs[0]
        $sMsg &= $i & ") " & $aArgs[$i] & @CRLF
    Next

    ToolTip($sMsg , Default, Default, "!! Wrong Number of parameters", 3)
    Sleep(4000)
EndIf

Exit

Func _main($sArg1, $sArg2, $sArg3, $sArg4)

    $filepath = $sArg1
    $sspath = $sArg2
    $sspath2 = $sArg3
    $option = $sArg4

    ControlFocus("Select Folder to Upload", "", "Edit1")

    If $option = "screenshot" Then
        popupIsDisplayed()
    ElseIf $option = "cancel" Then
        clickCancelInPopUp()
    ElseIf $option = "select file" Then
        selectFile()
        clickUploadInPopUp()
    ElseIf $option = "alert screenshot" Then
        alertISDisplayed()
    ElseIf $option = "upload" Then
        clickUploadInAlert()
    ElseIf $option = "cancel alert" Then
        clickCancelInAlert()
    EndIf

EndFunc   ;==>_main

Func popupIsDisplayed()
    ControlFocus("Select Folder to Upload", "", "Edit1")
    Sleep(2000)
    Example()
EndFunc   ;==>popupIsDisplayed

Func clickCancelInPopUp()
    ControlClick("Select Folder to Upload", "", "Button2")
EndFunc   ;==>clickCancelInPopUp

Func selectFile()
    ControlSetText("Select Folder to Upload", "", "Edit1", $filepath)
    Sleep(2000)
    Example()
    Sleep(2000)
EndFunc   ;==>selectFile

Func clickUploadInPopUp()
    ControlClick("Select Folder to Upload", "", "Button1")
    Sleep(2000)
EndFunc   ;==>clickUploadInPopUp

Func alertISDisplayed()
    Example2()
EndFunc   ;==>alertISDisplayed

Func clickUploadInAlert()
    Example2()
    Send("{Tab}")
    Send("{Enter}")
EndFunc   ;==>clickUploadInAlert

Func clickCancelInAlert()
    Example2()
    Send("{Enter}")
EndFunc   ;==>clickCancelInAlert

Func Example()
    Local $hBmp

    ; Capture full screen
    $hBmp = _ScreenCapture_Capture("")

    ; Save bitmap to file
    _ScreenCapture_SaveImage($sspath, $hBmp)
EndFunc   ;==>Example

Func Example2()
    Local $hBmp

    ; Capture full screen
    $hBmp = _ScreenCapture_Capture("")

    ; Save bitmap to file
    _ScreenCapture_SaveImage($sspath2, $hBmp)
EndFunc   ;==>Example2

 

I know that I know nothing

Posted
3 hours ago, Nine said:

Just pass a dummy parameter, like "NULL" or specific character like "*".  Anything beside nothing....

ps. In java you need to escape quotation marks if you want to send them, this would be a valid parameter "\"\"" and it would be interpreted as Null value in AutoIt (like suggested by @argumentum below)

Thank you!!!

Posted
4 minutes ago, ioa747 said:

my approach

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <ScreenCapture.au3>

Global $aArgs = $CmdLine
;~ Global $aArgs = [5, "one", 2, "three", "", "five"] ;test

Global $filepath, $sspath, $sspath2, $option

If $aArgs[0] = 4 Then
    $aArgs[0] = "CallArgArray"
    Call("_main", $aArgs)
Else
    Global $sMsg = "Number of parameters: " & $aArgs[0] & @CRLF
    For $i = 1 To $aArgs[0]
        $sMsg &= $i & ") " & $aArgs[$i] & @CRLF
    Next

    ToolTip($sMsg , Default, Default, "!! Wrong Number of parameters", 3)
    Sleep(4000)
EndIf

Exit

Func _main($sArg1, $sArg2, $sArg3, $sArg4)

    $filepath = $sArg1
    $sspath = $sArg2
    $sspath2 = $sArg3
    $option = $sArg4

    ControlFocus("Select Folder to Upload", "", "Edit1")

    If $option = "screenshot" Then
        popupIsDisplayed()
    ElseIf $option = "cancel" Then
        clickCancelInPopUp()
    ElseIf $option = "select file" Then
        selectFile()
        clickUploadInPopUp()
    ElseIf $option = "alert screenshot" Then
        alertISDisplayed()
    ElseIf $option = "upload" Then
        clickUploadInAlert()
    ElseIf $option = "cancel alert" Then
        clickCancelInAlert()
    EndIf

EndFunc   ;==>_main

Func popupIsDisplayed()
    ControlFocus("Select Folder to Upload", "", "Edit1")
    Sleep(2000)
    Example()
EndFunc   ;==>popupIsDisplayed

Func clickCancelInPopUp()
    ControlClick("Select Folder to Upload", "", "Button2")
EndFunc   ;==>clickCancelInPopUp

Func selectFile()
    ControlSetText("Select Folder to Upload", "", "Edit1", $filepath)
    Sleep(2000)
    Example()
    Sleep(2000)
EndFunc   ;==>selectFile

Func clickUploadInPopUp()
    ControlClick("Select Folder to Upload", "", "Button1")
    Sleep(2000)
EndFunc   ;==>clickUploadInPopUp

Func alertISDisplayed()
    Example2()
EndFunc   ;==>alertISDisplayed

Func clickUploadInAlert()
    Example2()
    Send("{Tab}")
    Send("{Enter}")
EndFunc   ;==>clickUploadInAlert

Func clickCancelInAlert()
    Example2()
    Send("{Enter}")
EndFunc   ;==>clickCancelInAlert

Func Example()
    Local $hBmp

    ; Capture full screen
    $hBmp = _ScreenCapture_Capture("")

    ; Save bitmap to file
    _ScreenCapture_SaveImage($sspath, $hBmp)
EndFunc   ;==>Example

Func Example2()
    Local $hBmp

    ; Capture full screen
    $hBmp = _ScreenCapture_Capture("")

    ; Save bitmap to file
    _ScreenCapture_SaveImage($sspath2, $hBmp)
EndFunc   ;==>Example2

 

Thank you!!!

Posted
3 hours ago, argumentum said:

just do it.

For $n = 1 To $CmdLine[0]
    ConsoleWrite($n & @TAB & '>' & $CmdLine[$n] & '<' & @CRLF)
Next
Exit

I passed 1 "" 3 4 and got

1   >1<
2   ><
3   >3<
4   >4<

so yes you can.


What I would do in your case is

Global $option, $filepath, $sspath, $sspath2
If $CmdLine[0] > 3 Then $option = $CmdLine[4]
If $CmdLine[0] > 0 Then $filepath = $CmdLine[1]
If $CmdLine[0] > 1 Then $sspath =$CmdLine[2]
If $CmdLine[0] > 2 Then $sspath2 = $CmdLine[3]

so you don't get the error you got with your code.
 

Then again, you'll have to learn to think and explore on your own. My 2 cents even if you don't like it

Thank you!!!

Posted
3 hours ago, SatheshVp said:

@JosThanks, I found where the issue is. Array in AutoIt is not considering null value(""). 

 

Actual:

$CmdLine[0] = number of items

$CmdLine[1] = folder path

$CmdLine[2] = SSPath

$CmdLine[3] ="select file"

 

Expected:

$CmdLine[0] = number of items

$CmdLine[1] = folder path

$CmdLine[2] = SSPath

$CmdLine[3] = ""

$CmdLine[4] ="select file"

 

How can we pass null value ("")?

Thank you!!!

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
  • Recently Browsing   0 members

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