gcue Posted April 30, 2008 Share Posted April 30, 2008 (edited) hello. i started to get "error: arrage variable has incorrect number of subscripts or subscript dimesnion range exceeded." Once i started to use stringsplit. are there some strings that can't be split err whats the deal? $user = RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Altiris Agent\Inventory", "PrimaryUser") $version = RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Bloomberg L.P.\Components", "sotr_version") $usr=StringSplit($user,"\") $ver=StringSplit($version," ") FileWrite($file, '' &@CRLF & _ $usr[2] & "," & $ver[2]) Edited April 30, 2008 by gcue Link to comment Share on other sites More sharing options...
Developers Jos Posted April 30, 2008 Developers Share Posted April 30, 2008 You are not checking the $usr[0] and $ver[0] to see the number of entries in the array. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
gcue Posted April 30, 2008 Author Share Posted April 30, 2008 what do you mean? how do i check [0] ? Link to comment Share on other sites More sharing options...
Developers Jos Posted April 30, 2008 Developers Share Posted April 30, 2008 what do you mean? how do i check [0] ?Have you looked in the Helpfile? Return Value Returns an array, the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) contain the delimited strings. If no delimiters were found @error is set to 1, the count is 1 ($array[0]) and the full string is returned ($array[1]). SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
gcue Posted May 1, 2008 Author Share Posted May 1, 2008 hmm im still confused. i get that usr[0] has the number of strings so why would i have to bring that out? or how do i? Link to comment Share on other sites More sharing options...
Developers Jos Posted May 1, 2008 Developers Share Posted May 1, 2008 hmm im still confused. i get that usr[0] has the number of strings so why would i have to bring that out? or how do i?You refer to $usr[2], but you have not tested if that really exists. When $usr[0] is 2 or greater it will be there. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
gcue Posted May 1, 2008 Author Share Posted May 1, 2008 and if its not? thats where i run into the error right? so i should do... if $usr[0] = 0 then $usr[0] = 1 EndIF ?? Link to comment Share on other sites More sharing options...
Developers Jos Posted May 1, 2008 Developers Share Posted May 1, 2008 and if its not? thats where i run into the error right? so i should do... if $usr[0] = 0 then $usr[0] = 1 EndIF ??thats up to you what to do when the returned array doesn't contain the required values. SO what do you want to do in that case ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
gcue Posted May 1, 2008 Author Share Posted May 1, 2008 ahhh i can msgbox saying that array was empty... =D so thats what you meant by: "You are not checking the $usr[0] and $ver[0] to see the number of entries in the array." i have to do something just in case they are 0 =) Link to comment Share on other sites More sharing options...
gcue Posted May 1, 2008 Author Share Posted May 1, 2008 hmm i still get the same error $usr=StringSplit($user,"\") if $usr[0] = 0 then Msgbox(0,"Backup XLBs", $assets[$x] & " does not have a primary user.") EndIF Link to comment Share on other sites More sharing options...
Developers Jos Posted May 1, 2008 Developers Share Posted May 1, 2008 hmm i still get the same error $usr=StringSplit($user,"\") if $usr[0] = 0 then Msgbox(0,"Backup XLBs", $assets[$x] & " does not have a primary user.") EndIFWhat Line and what Array do you get the error for? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
someone Posted May 1, 2008 Share Posted May 1, 2008 (edited) Not to step on your toes Jos... If there was an error with stringsplit, this is what the helpfile says will be returned... "If no delimiters were found @error is set to 1, the count is 1 ($array[0]) and the full string is returned ($array[1])." Meaning if stringsplit caused an error, the array will not have a 2 element. You can error check for that by checking @error after stringsplit (what I would do), or by checking if $array[1] is the entire string, or by doing a Ubound on $array to see if it goes up to 2. Edited May 1, 2008 by someone While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd Link to comment Share on other sites More sharing options...
gcue Posted May 1, 2008 Author Share Posted May 1, 2008 ok im getting closer.... i still get the error when it doesnt find the array If @error Then Msgbox(0,"Backup XLBs", $assets[$x] & " does not have a primary user.") EndIf it does the msgbox but what do i do after that? i tried setting $usr[2] to a valid answer but i still get the error. =/ Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 1, 2008 Moderators Share Posted May 1, 2008 (edited) The point that Jos is trying to make, is that you need [2] to be filled by something. You are assuming that [2] will always have something though.Your condition statement should be something like:If ($assets[0] <> 2) Then Continueloop;Rest of code hereThat way, you'll never get the exception thrown if your code is under the continueloop. 1 line fixes the whole issue.Of course, this is if you only want information with 2 elements [1] and [2].If you're not in a loop and you don't care about how many elements there are:If ($assets[0] > 1) Then do something with both elements: $assets[1] & $assets[2] Else do something with only the first element: $asset[1] EndIfIt's array management, since it seems you are having an issue with understanding maybe how arrays work (or think maybe that every return will always have 2+ elements), you might take some time to think of some proper error handling on your own.This is also a good link: http://www.autoitscript.com/wiki/index.php?title=Arrays Edited May 1, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Developers Jos Posted May 1, 2008 Developers Share Posted May 1, 2008 (edited) Not to step on your toes Jos... If there was an error with stringsplit, this is what the helpfile says will be returned... "If no delimiters were found @error is set to 1, the count is 1 ($array[0]) and the full string is returned ($array[1])." Meaning if stringsplit caused an error, the array will not have a 2 element. You can error check for that by checking @error after stringsplit (what I would do), or by checking if $array[1] is the entire string, or by doing a Ubound on $array to see if it goes up to 2.Don't worry stepping on my toes:) Isn't testing for "$array[0] > 1" enough to ensure that the $array[2] doesn't cause an error like posted ? Should work as far as I can tell. Edited May 1, 2008 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
gcue Posted May 1, 2008 Author Share Posted May 1, 2008 that worked! $usr=StringSplit($user,"\") If @error Then Msgbox(0,"Backup XLBs", $assets[$x] & " does not have a primary user.") ContinueLoop EndIf thank you much fellas. 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