Jump to content
Sign in to follow this  
gcue

array variable has incorrect number of...

Recommended Posts

gcue

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 by gcue

Share this post


Link to post
Share on other sites
gcue

what do you mean? how do i check [0] ?

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
gcue

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?

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
gcue

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

??

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
gcue

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 =)

Share this post


Link to post
Share on other sites
gcue

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

Share this post


Link to post
Share on other sites
Jos

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

What 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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
someone

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 by someone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites
gcue

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.

=/

Share this post


Link to post
Share on other sites
SmOke_N

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 here

That 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]
EndIf

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

Share this post


Link to post
Share on other sites
Jos

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 by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
gcue

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.

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  

×