great77 Posted October 5, 2015 Share Posted October 5, 2015 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^ ERRORThe 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 isexpandcollapse popup#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 More sharing options...
Moderators Melba23 Posted October 5, 2015 Moderators Share Posted October 5, 2015 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 great77 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
great77 Posted October 5, 2015 Author Share Posted October 5, 2015 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.M23Thanks Melba23 . Much appreciated. Will do the aforementioned. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now