Sign in to follow this  
Followers 0
HockeyFan

Error using _ArraySearch when search value not found

6 posts in this topic

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!

Share this post


Link to post
Share on other sites



HockeyFan,

I'm pretty sure I'm getting the above error message becuase the _ArraySearch is not finding the "$sSearchName" variable in the array

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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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! :)

Share this post


Link to post
Share on other sites

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

 

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