Sign in to follow this  
Followers 0
TheCrimsonCrusader

Receiving "Error: Subscript used with non-Array variable." Error Message

11 posts in this topic

Hello,

I believe this erorr message is coming from the DriveGetDrive calls to the USB flash drive, but I have no clue how to fix.  If anyone has any ideas, it would be greatly appreciated!

Opt("TrayIconHide", 1)

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3> 

Dim $yyyymd, $TodaysDateIs, $TodaysDateIs, $FindUSBFlashDrive, $file, $DateDiffTotal, $USBDriveLocation


;Check if USB offline media has expired - START
$TodaysDateIs = (@YEAR & "/" & @MON & "/" & @MDAY)


Local $USBdrive = DriveGetDrive("REMOVABLE"), $USBFileLocationName = '\SMS\data\policy.xml'
If Not @error Then 
    For $i = 1 To UBound($USBdrive) - 1
        If FileExists($USBdrive[$i] & $USBFileLocationName) Then 
            $USBDriveLocation = $USBdrive[$i]
        EndIf
    Next
Else
EndIf


$file = $USBDriveLocation & "\SMS\data\policy.xml"


$FileDate = FileGetTime($file, 0, 0)


If FileExists($file) Then
$yyyymmdd = $FileDate[0] & "/" & $FileDate[1] & "/" & $FileDate[2]
$DateDiffTotal = _DateDiff( 'D',$yyyymmdd,$TodaysDateIs)
EndIf


If $DateDiffTotal > 730 Then
MsgBox(262160,"Expired SCCM Boot Image Media", "This image boot media has expired as it is 2 or more years old." & @CRLF & @CRLF & "Please download the latest media from the following location:" & @CRLF & @CRLF & "such and such locationl"& @CRLF & @CRLF & "Pressing the OK button will shut down the machine.")
RunWait("wpeutil shutdown","",@SW_HIDE)
Exit
Else
EndIf
;Check if USB offline media has expired - END


;Bypass Bare Metal/Refresh GUI - START
$FindUSBFlashDrive = DriveGetDrive( "REMOVABLE" )
If not @error Then
For $i = 1 to $FindUSBFlashDrive[0]
If FileExists($FindUSBFlashDrive[$i] & "\BypassImageType.txt") Then Exit
Sleep(1000)
Next
EndIf
;Bypass Bare Metal/Refresh GUI - END


$FindUSBFlashDrive = DriveGetDrive( "REMOVABLE" )
If not @error Then
For $i = 1 to $FindUSBFlashDrive[0]
Local $t = FileGetTime($FindUSBFlashDrive[$i] & "\SMS\data\policy.xml", 1)


Sleep(1000)
Next
EndIf


;The +2 below represents 2 years being added to the original file creation date.  The -1 below represents 1 day being subtracted from the original creation "day".  This done to throw off someone looking for a similar date stamp to try to cheat the system.
If Not @error Then
    Local $yyyymd = $t[0]+2 & "/" & $t[1] & "/" & $t[2]-1
EndIf


GUICreate("HalOSD", 500, 280,-1,-1,BitOR($WS_DLGFRAME, $WS_EX_TOPMOST), 0)


WinSetOnTop("HalOSD","",1)


GUICtrlCreatePic("x:\HalLogo.jpg",6,8,485,70)


;This creates the red top border.
GUICtrlCreateGraphic(5,5,490,1)
GUICtrlSetGraphic(-1, $GUI_GR_LINE)
GUICtrlSetColor(-1,0xff0000)


;This creates red second horizontal bar.
GUICtrlCreateGraphic(5,78,490,1)
GUICtrlSetGraphic(-1, $GUI_GR_LINE)
GUICtrlSetColor(-1,0xff0000)


;This creates the red bottom border.
GUICtrlCreateGraphic(5,252,490,1)
GUICtrlSetGraphic(-1, $GUI_GR_LINE)
GUICtrlSetColor(-1,0xff0000)


;This creates the red left border.
GUICtrlCreateGraphic(5,5,1,248)
GUICtrlSetGraphic(-1, $GUI_GR_LINE)
GUICtrlSetColor(-1,0xff0000)


;This creates the red right border.
GUICtrlCreateGraphic(494,5,1,248)
GUICtrlSetGraphic(-1, $GUI_GR_LINE)
GUICtrlSetColor(-1,0xff0000)


If FileExists($file) Then
GuiCtrlCreateLabel("This image media expires on " & $yyyymd,40,90,420,28,$SS_CENTER)
GUICtrlSetFont (-1,10, 800)
GUICtrlSetColor(-1,0xff0000)
EndIf


GuiCtrlCreateLabel("Please select an option below:",50,135,350,28)
GUICtrlSetFont (-1,10, 800)
$OSDrive0 = GUICtrlCreateButton("  1.  Bare Metal Image", 50, 175, 350, 28,$BS_LEFT)
GUICtrlSetFont (-1,-1, 800)
$BareMetalHelp = GUICtrlCreateButton("?", 430, 175, 20, 28)
GUICtrlSetFont (-1,-1, 800)
$DataDrive1 = GUICtrlCreateButton("  2.  Refresh Image", 50, 215, 350, 28,$BS_LEFT)
GUICtrlSetFont (-1,-1, 800)
$RefreshHelp = GUICtrlCreateButton("?", 430, 215, 20, 28)
GUICtrlSetFont (-1,-1, 800)

 
GUISetState(); display the GUI

 
Do
    $msg = GUIGetMsg()
 
    Select
         Case $msg = $OSDrive0
            $YeahOrNeah = MsgBox(262180,"Bare Metal Image","**WARNING**  You selected the bare metal image option, which will wipe the drive including all user data.  Do you wish to continue?")
            If $YeahOrNeah = "6" Then
            $CompName="x:\ImageType.wsf"
            FileWriteLine("x:\ImageType.wsf","<job id=" & chr(34) & "ZTIPromptForComputerName" & chr(34) & ">")
            FileWriteLine("x:\ImageType.wsf","<script language=" & chr(34) & "VBScript" & chr(34) & " src=" & chr(34) & "ZTIUtility.vbs" & chr(34) & "/>")
            FileWriteLine("x:\ImageType.wsf","<script language=" & chr(34) & "VBScript" & chr(34) & ">")
            FileWriteLine("x:\ImageType.wsf","Option Explicit")
            FileWriteLine("x:\ImageType.wsf","Dim numCount")
            FileWriteLine("x:\ImageType.wsf","Dim strComputerName")
            FileWriteLine("x:\ImageType.wsf","Dim objOSD")
            FileWriteLine("x:\ImageType.wsf","oEnvironment.Item" & chr(40) & chr(34) & "BareMetalImage" & chr(34) & chr(41) & " = " & chr(34) & "BareMetalImage" & chr(34))
            FileWriteLine("x:\ImageType.wsf","</script>")
            FileWriteLine("x:\ImageType.wsf","</job>")
            RunWait("cscript.exe" & " x:\ImageType.wsf","",@SW_HIDE)
            Exit
            EndIf
         Case $msg = $DataDrive1
            $CompName="x:\ImageType.wsf"
            FileWriteLine("x:\ImageType.wsf","<job id=" & chr(34) & "ZTIPromptForComputerName" & chr(34) & ">")
            FileWriteLine("x:\ImageType.wsf","<script language=" & chr(34) & "VBScript" & chr(34) & " src=" & chr(34) & "ZTIUtility.vbs" & chr(34) & "/>")
            FileWriteLine("x:\ImageType.wsf","<script language=" & chr(34) & "VBScript" & chr(34) & ">")
            FileWriteLine("x:\ImageType.wsf","Option Explicit")
            FileWriteLine("x:\ImageType.wsf","Dim numCount")
            FileWriteLine("x:\ImageType.wsf","Dim strComputerName")
            FileWriteLine("x:\ImageType.wsf","Dim objOSD")
            FileWriteLine("x:\ImageType.wsf","oEnvironment.Item" & chr(40) & chr(34) & "RefreshImage" & chr(34) & chr(41) & " = " & chr(34) & "RefreshImage" & chr(34))
            FileWriteLine("x:\ImageType.wsf","</script>")
            FileWriteLine("x:\ImageType.wsf","</job>")
            RunWait("cscript.exe" & " x:\ImageType.wsf","",@SW_HIDE)
            Exit
         Case $msg = $BareMetalHelp
            MsgBox(262208,"Bare Metal Image","The bare metal image option wipes all data from the hard drive and then reimages the machine.")
         Case $msg = $RefreshHelp
            MsgBox(262208,"Refresh Image","The refresh image option backs up the user data, wipes the drive except for the user data, reimages the machine and then restores the user data.")
    EndSelect
Until $msg = $GUI_EVENT_CLOSE
;EndIf

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Can you post the full error message from the console, so that we can see exactly where it is having an error? :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

I can't replicate the problem on my end.  I have a user that is running into the problem from the compiled executable.  It's somewhat a random problem and it doesn't happen most of the time, which is makes it more confusing.  The USB key is inserted and the path to the policy.xml file exists along with the policy.xml file.  Thanks.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Before you work with any array, you should do a check that the UBound of it is >= what you are attempting to pull.

This is required for scripts that you don't want to crash in all situations.

Local $array[5]=[1,2,3,4,5]

ConsoleWrite("start1" & @CRLF)
; won't error out
If UBound($array)>=6 Then
    MsgBox(1,1,$array[6])
EndIf

ConsoleWrite("start2" & @CRLF)
; will error out
MsgBox(1,1,$array[6])

output:

 start1
start2
C:test.aU3 (##) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
MsgBox(1,1,$array[6])
MsgBox(1,1,^ ERROR

 

The above stops the symptom.  The actual issue is that what you are expecting to be an array is probably not.  You should do loops or error checks on the function that creates the array, until it actually returns one.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

When that error occurs, it will always give a line number no matter if it is compiled or not (if it is compiled it will pop up a MsgBox with the line number in parenthesis; not compiled it will go to the console). Since it is from the .exe compiled file, it will give you the line number from the compiled program. To find this line, you'll need to get the stripped au3 file at the time of compile and look at the line number. This can be done by putting these directives in your source:

#Region ; make sure this is at the complete top
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so
#EndRegion

And then compiling it. It will also tell you if you have any errors in the console as well when compiling.

Alas, until you can get that information, I can only stab at the problem.

Try this:

Opt("TrayIconHide", 1)

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3>

Dim $yyyymd, $TodaysDateIs, $TodaysDateIs, $FindUSBFlashDrive, $file, $DateDiffTotal, $USBDriveLocation


;Check if USB offline media has expired - START
$TodaysDateIs = (@YEAR & "/" & @MON & "/" & @MDAY)

Local $USBdrive = DriveGetDrive("REMOVABLE"), $USBFileLocationName = '\SMS\data\policy.xml'
If Not @error Then
    For $i = 1 To UBound($USBdrive) - 1
        If FileExists($USBdrive[$i] & $USBFileLocationName) Then
            $USBDriveLocation = $USBdrive[$i]
        EndIf
    Next
Else
EndIf


$file = $USBDriveLocation & "\SMS\data\policy.xml"


$FileDate = FileGetTime($file, 0, 0)
If Not IsArray($FileDate) Then ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Return value could be a string
    If FileExists($file) Then
            $yyyymmdd = $FileDate                                                ;<<
          $DateDiffTotal = _DateDiff('D', $yyyymmdd, $TodaysDateIs)            ;<<    
       EndIf                                                              ;<<
Else                                                                       ;<<
    If FileExists($file) Then
        $yyyymmdd = $FileDate[0] & "/" & $FileDate[1] & "/" & $FileDate[2]
        $DateDiffTotal = _DateDiff('D', $yyyymmdd, $TodaysDateIs)
    EndIf
EndIf

If $DateDiffTotal > 730 Then
    MsgBox(262160, "Expired SCCM Boot Image Media", "This image boot media has expired as it is 2 or more years old." & @CRLF & @CRLF & "Please download the latest media from the following location:" & @CRLF & @CRLF & "such and such locationl" & @CRLF & @CRLF & "Pressing the OK button will shut down the machine.")
    RunWait("wpeutil shutdown", "", @SW_HIDE)
    Exit
Else
EndIf
;Check if USB offline media has expired - END


;Bypass Bare Metal/Refresh GUI - START
$FindUSBFlashDrive = DriveGetDrive("REMOVABLE")
If Not @error Then
    For $i = 1 To $FindUSBFlashDrive[0]
        If FileExists($FindUSBFlashDrive[$i] & "\BypassImageType.txt") Then Exit
        Sleep(1000)
    Next
EndIf
;Bypass Bare Metal/Refresh GUI - END


$FindUSBFlashDrive = DriveGetDrive("REMOVABLE")
If Not @error Then
    For $i = 1 To $FindUSBFlashDrive[0]
        Local $t = FileGetTime($FindUSBFlashDrive[$i] & "\SMS\data\policy.xml", 1)


        Sleep(1000)
    Next
EndIf


;The +2 below represents 2 years being added to the original file creation date.  The -1 below represents 1 day being subtracted from the original creation "day".  This done to throw off someone looking for a similar date stamp to try to cheat the system.
If Not @error Then
    Local $yyyymd = $t[0] + 2 & "/" & $t[1] & "/" & $t[2] - 1
EndIf
GUICreate("HalOSD", 500, 280, -1, -1, BitOR($WS_DLGFRAME, $WS_EX_TOPMOST), 0)


WinSetOnTop("HalOSD", "", 1)


GUICtrlCreatePic("x:\HalLogo.jpg", 6, 8, 485, 70)


;This creates the red top border.
GUICtrlCreateGraphic(5, 5, 490, 1)
GUICtrlSetGraphic(-1, $GUI_GR_LINE)
GUICtrlSetColor(-1, 0xff0000)


;This creates red second horizontal bar.
GUICtrlCreateGraphic(5, 78, 490, 1)
GUICtrlSetGraphic(-1, $GUI_GR_LINE)
GUICtrlSetColor(-1, 0xff0000)


;This creates the red bottom border.
GUICtrlCreateGraphic(5, 252, 490, 1)
GUICtrlSetGraphic(-1, $GUI_GR_LINE)
GUICtrlSetColor(-1, 0xff0000)


;This creates the red left border.
GUICtrlCreateGraphic(5, 5, 1, 248)
GUICtrlSetGraphic(-1, $GUI_GR_LINE)
GUICtrlSetColor(-1, 0xff0000)


;This creates the red right border.
GUICtrlCreateGraphic(494, 5, 1, 248)
GUICtrlSetGraphic(-1, $GUI_GR_LINE)
GUICtrlSetColor(-1, 0xff0000)


If FileExists($file) Then
    GUICtrlCreateLabel("This image media expires on " & $yyyymd, 40, 90, 420, 28, $SS_CENTER)
    GUICtrlSetFont(-1, 10, 800)
    GUICtrlSetColor(-1, 0xff0000)
EndIf


GUICtrlCreateLabel("Please select an option below:", 50, 135, 350, 28)
GUICtrlSetFont(-1, 10, 800)
$OSDrive0 = GUICtrlCreateButton("  1.  Bare Metal Image", 50, 175, 350, 28, $BS_LEFT)
GUICtrlSetFont(-1, -1, 800)
$BareMetalHelp = GUICtrlCreateButton("?", 430, 175, 20, 28)
GUICtrlSetFont(-1, -1, 800)
$DataDrive1 = GUICtrlCreateButton("  2.  Refresh Image", 50, 215, 350, 28, $BS_LEFT)
GUICtrlSetFont(-1, -1, 800)
$RefreshHelp = GUICtrlCreateButton("?", 430, 215, 20, 28)
GUICtrlSetFont(-1, -1, 800)


GUISetState(); display the GUI
Do
    $msg = GUIGetMsg()

    Select
        Case $msg = $OSDrive0
            $YeahOrNeah = MsgBox(262180, "Bare Metal Image", "**WARNING**  You selected the bare metal image option, which will wipe the drive including all user data.  Do you wish to continue?")
            If $YeahOrNeah = "6" Then
                $CompName = "x:\ImageType.wsf"
                FileWriteLine("x:\ImageType.wsf", "<job id=" & Chr(34) & "ZTIPromptForComputerName" & Chr(34) & ">")
                FileWriteLine("x:\ImageType.wsf", "<script language=" & Chr(34) & "VBScript" & Chr(34) & " src=" & Chr(34) & "ZTIUtility.vbs" & Chr(34) & "/>")
                FileWriteLine("x:\ImageType.wsf", "<script language=" & Chr(34) & "VBScript" & Chr(34) & ">")
                FileWriteLine("x:\ImageType.wsf", "Option Explicit")
                FileWriteLine("x:\ImageType.wsf", "Dim numCount")
                FileWriteLine("x:\ImageType.wsf", "Dim strComputerName")
                FileWriteLine("x:\ImageType.wsf", "Dim objOSD")
                FileWriteLine("x:\ImageType.wsf", "oEnvironment.Item" & Chr(40) & Chr(34) & "BareMetalImage" & Chr(34) & Chr(41) & " = " & Chr(34) & "BareMetalImage" & Chr(34))
                FileWriteLine("x:\ImageType.wsf", "</script>")
                FileWriteLine("x:\ImageType.wsf", "</job>")
                RunWait("cscript.exe" & " x:\ImageType.wsf", "", @SW_HIDE)
                Exit
            EndIf
        Case $msg = $DataDrive1
            $CompName = "x:\ImageType.wsf"
            FileWriteLine("x:\ImageType.wsf", "<job id=" & Chr(34) & "ZTIPromptForComputerName" & Chr(34) & ">")
            FileWriteLine("x:\ImageType.wsf", "<script language=" & Chr(34) & "VBScript" & Chr(34) & " src=" & Chr(34) & "ZTIUtility.vbs" & Chr(34) & "/>")
            FileWriteLine("x:\ImageType.wsf", "<script language=" & Chr(34) & "VBScript" & Chr(34) & ">")
            FileWriteLine("x:\ImageType.wsf", "Option Explicit")
            FileWriteLine("x:\ImageType.wsf", "Dim numCount")
            FileWriteLine("x:\ImageType.wsf", "Dim strComputerName")
            FileWriteLine("x:\ImageType.wsf", "Dim objOSD")
            FileWriteLine("x:\ImageType.wsf", "oEnvironment.Item" & Chr(40) & Chr(34) & "RefreshImage" & Chr(34) & Chr(41) & " = " & Chr(34) & "RefreshImage" & Chr(34))
            FileWriteLine("x:\ImageType.wsf", "</script>")
            FileWriteLine("x:\ImageType.wsf", "</job>")
            RunWait("cscript.exe" & " x:\ImageType.wsf", "", @SW_HIDE)
            Exit
        Case $msg = $BareMetalHelp
            MsgBox(262208, "Bare Metal Image", "The bare metal image option wipes all data from the hard drive and then reimages the machine.")
        Case $msg = $RefreshHelp
            MsgBox(262208, "Refresh Image", "The refresh image option backs up the user data, wipes the drive except for the user data, reimages the machine and then restores the user data.")
    EndSelect
Until $msg = $GUI_EVENT_CLOSE
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

OK, got a screenshot.  It's line 3940. I will have to check out the AU3 stripper that you mentioned.  Thanks for the additional info.

Share this post


Link to post
Share on other sites

My pleasure. ;)

Please let us know how it goes, and post any questions you have. :)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Well, if I run it in a HyperV session, I always get the "Error: Subscript used with non-Array variable" error in this section:

If Not @error Then
    Local $yyyymd = $t[0]+2 & "/" & $t[1] & "/" & $t[2]-1
EndIf

Any ideas?  If I had an Else statement after the local line to call a MsgBox call (just for testing), it still bombs with the error.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

an array or string that contains the file time information.

This is the remark for FileGetTime()

Try this:

Local $prev_error = @error

If Not IsArray($t) Then
    If $prev_error = 0 Then
        Local $tEx = StringSplit($t, "/")
        Local $yyyymd = $tEx[1] + 2 & "/" & $tEx[2] & "/" & $tEx[3] - 1
    EndIf
Else
    If $prev_error = 0 Then
        Local $yyyymd = $t[1] + 2 & "/" & $t[2] & "/" & $t[3] - 1
    EndIf
EndIf
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

@error is cleared out by IsArray...you'd have to set the error to a variable, and use that.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

@error is cleared out by IsArray...you'd have to set the error to a variable, and use that.

good catch, updated post #9


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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