Jump to content

Subscript used on non-accessible variable


Recommended Posts

Hi Guys,

This forum has been helpful and some problems have been solved through looking at various solutions on this site. I am having problem with this code below and I have tried to look at the code and it was working initially and then stop working. Please any way to solve this and make it work without coming with this error. The error is  ==> Subscript used on non-accessible variable.:
$SER1 = StringTrimLeft($test[0], 1 )
$SER1 = StringTrimLeft($test^ ERROR

The program is searching through a file and then extract the first five digit of the filename and also go into one of the file in the folder and then search .vhd and look at a serial number of a particular AC.

 

Please looking forward to any ideas.

Code is

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y

#Include <File.au3>
#Include <Array.au3>
#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <Process.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("TrayMenuMode", 1) ;0=append, 1=no default menu,
Opt("TrayAutoPause", 0) ;0=no pause, 1=Pause
Global $i = ""


Global Const $SEM_FAILCRITICALERRORS = 1
Local $begin, $aInput, $MyString1, $result, $i, $IN, $sLine, $dif, $test, $test2, $MyBox, $REG1, $REG2,$FileList,$SER1,$SER2,$Name,$Extract

SetErrorMode($SEM_FAILCRITICALERRORS)

ConsoleWrite(FileOpen("A:") & @CRLF) ; 


Func SetErrorMode($iMode)
    Local $aCall = DllCall("kernel32.dll", "dword", "SetErrorMode", "dword", $iMode)
    If @error Then Return SetError(1, 0, 0)
    Return $aCall[0]
EndFunc

Global $TimeToRun = 0.11; The number of minutes in seconds n * 60
$TimeToRun = $TimeToRun * 60000
Global $Timer = TimerInit()



If FileExists("C:\BACKUPS\unregistered_AC\*.*") Then
$FileList = _FileListToArray("C:\BACKUPS\unregistered_AC")
For $i = 1 To UBound($FileList)- 1
    If FileExists("C:\BACKUPS\unregistered_AC\" & $FileList[$i] & "\vibabort.hsd") Then
    $IN = FileOpen("C:\BACKUPS\unregistered_AC\" &  $FileList[$i] & "\vibabort.hsd", 0 )

EndIf

While 1

   $sLine = FileReadLine($IN)
   $test = StringRegExp($sLine,'(\b(?:831)\d{3}\b)',3)
   $Extract = $FileList[$i]
SLEEP(1000)
;; _arraydisplay( $test ,"$test") ;; use this to test
   if @error = -1 Then ExitLoop

If @error == 0 Then
sleep(2000)

;MsgBox(4," AC Information: ","The serial number is " & $test[0] , 15) ;This is testing
$SER1 = StringTrimLeft($test[0], 1 )


sleep(1000)
$REG1 = StringTrimRight($FileList[$i], 18 )
sleep(2000)
; MsgBox(4," AC Information & The Registration: ","The regisstration is : "  & $REG1  , 15); This is testing
   sleep(1000)

MsgBox(4," AC Information: ","The Registration number is " & $REG1  & "  and the Serial number is " & $test[0] , 15) 


   SLEEP(1000)



Else
$test2 = StringRegExp($sLine,'(\b(?:841)\d{3}\b)',3)
sleep(1000)
 ;MsgBox(4," AC Information: ","The serial number is " & $test2[0] , 15) ;This is testing

$SER2 = StringTrimLeft($test2[0], 1 )

$REG2 = StringTrimRight($FileList[$i], 18)
sleep(1000)
 ;MsgBox(4," AC Information & The Registration: ","The regisstration is : "  & $REG2  , 15); This is testing
sleep(1000)

MsgBox(4," AC Information: ","The Registration number is " & $REG2  & "  and the Serial number is " & $test2[0] , 15) 

ExitLoop



 EndIf
 sleep(1000)


WEnd
ExitLoop
Next

EndIf

 

Link to comment
Share on other sites

  • Moderators

great77,

Welcome to the AutoIt forums.

The reason you are getting the error is that at some point your RegEx is not returning any matches from a line of the file - so there is no $test array to access. So I suggest you add some errorchecking in your code to cater for this event - then the error will not occur.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

great77,

Welcome to the AutoIt forums.

The reason you are getting the error is that at some point your RegEx is not returning any matches from a line of the file - so there is no $test array to access. So I suggest you add some errorchecking in your code to cater for this event - then the error will not occur.

M23

Thanks  Melba23 . Much appreciated. Will do the aforementioned.

 

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