HockeyFan Posted May 8, 2012 Share Posted May 8, 2012 Hello! Would someone be able to offer some insight into how to resolve the following error message? Error: Array variable has incorrect number of subscripts or subscripts demension rage exceeded. I'm pretty sure I'm getting the above error message becuase the _ArraySearch is not finding the "$sSearchName" variable in the array. When the "Log.txt" file contains the search variable, all is good. When a the "Log.txt" file does not contain the search variable, the script produces the above error message. Is there something that I can change that will make the "_ArraySearch" not error out when it does not find the search criteria? Here is my code: If Not _FileReadToArray("C:\Program Files\ProgramName\Log.txt", $aRecords) Then MsgBox(0, "Error", "File not found") Exit EndIf ;Test to see array detail _ArrayDisplay($aRecords, "$avArray") $sSearchName = "Machine name" $iIndex = _ArraySearch($aRecords, $sSearchName, 0, 0, 0, 1) If @error Then MsgBox(0, "Not Found", '"' & $sSearchName & '" was not found in the array.') Else MsgBox(0, "Found", '"' & $sSearchName & '" was found in the array at position ' & $iIndex & ".") EndIf Exit Here is a small sample of what the "log.txt" file contains: 12/6/2011 7:41:33 AM ------------------------------------------------------------------------------------------ 12/6/2011 7:41:33 AM Starting 12/6/2011 7:41:33 AM Applying fix 12/6/2011 7:41:33 AM Starting synchronization 12/6/2011 7:41:33 AM Address=10.0.0.1 12/6/2011 7:41:33 AM Port=1234 12/6/2011 7:41:33 AM Authenticate=Yes 12/6/2011 7:41:33 AM Starting boot protection installation 12/6/2011 7:41:41 AM Machine name = HR767BVW1 12/6/2011 7:41:45 AM Creating new machine database entry Thanks! Link to comment Share on other sites More sharing options...
Bert Posted May 8, 2012 Share Posted May 8, 2012 (edited) Look at the command SetError in the helpfile Edited May 8, 2012 by Bellicus The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 8, 2012 Moderators Share Posted May 8, 2012 HockeyFan,I'm pretty sure I'm getting the above error message becuase the _ArraySearch is not finding the "$sSearchName" variable in the arrayThe code you posted works fine for me both with and without the search string in the array. I would be very surprised if _ArraySearch gave you that error - it is a pretty well-known function. Are you running the script from within SciTE? If so which line of the script is giving you the error? M23 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...
HockeyFan Posted May 8, 2012 Author Share Posted May 8, 2012 M23, I'm running the script as an exe on some test systems for righ now. I was only getting the error mesasge on the system that did not contain the search variable in the Log.txt file so I guess my assumptions were wrong...go figure! Let me install AutoIt and SciTE one of the test systems and see where that leads me. Thanks for jolting some of the cobwebs loose and steering me in a different direction. Link to comment Share on other sites More sharing options...
HockeyFan Posted May 8, 2012 Author Share Posted May 8, 2012 M23, Once again, you are brilliant!! The error was being generated becuase there was another instance of the search criteria "machine name" in the log file that I was unaware of...I was only expecting one instance at the beginning of the file. Here is the unexpected entry found... 2/6/2012 2:00:34 PM Changing local machine name to "PUBS767BVW1" ...so when I attempt to strip the computer name out, it generated the error because there was no [2] element in the array due to no delimiter being present. $ComputerNameLineStripWS = StringStripWS($aRecords[$iIndex], 8) $NameLineArray = StringSplit ($ComputerNameLineStripWS , "=", 0) $CopmuterName = $NameLineArray[2] I guess I need to change the search criteria to: $sSearchName = "Machine name =" Thanks again for your assistance! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 8, 2012 Moderators Share Posted May 8, 2012 HockeyFan, I only acted as the catalyst - glad you found the problem. M23 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...
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