Sign in to follow this  
Followers 0
Lutix

Array variable has incorrect number of subscripts error

17 posts in this topic

Well I have spent the last 3 hours trying to figure this out, I have searched the forum but found nothing relevant; what I'm trying to do is extremely simple and does not give me an error when I test using the code below:

Func InverseSM($datavlansubnet)
    $invoctettemp = StringSplit($datavlansubnet, ".")
    $invsubmask = 255 - $invoctettemp[1] & "."  & 255 - $invoctettemp[2] & "." & 255 - $invoctettemp[3] & "." & 255 - $invoctettemp[4]
    return $invsubmask
        EndFunc 
        $datavlansubnet = "255.255.255.128"
        $something = InverseSM($datavlansubnet)
        MsgBox(0,"blah",$something)

When I attempt to add the exact same function and run it in a 500 line script but I get the following error:

Array variable has incorrect number of subscripts or subscript dimension range exceeded

Note that the 500 line scripts runs fine without the function above.

The 500 line script consists of the following, there is a lot of concatenation but I believe the limit is reached on a line per line basis:

Send("enable" & "{ENTER}")
    Send("conf t" & "{ENTER}")

    Send("ip domain-name " & $domain & "{ENTER}")
    Send("hostname " & $hostname & "{ENTER}")
    Send("crypto key zeroize rsa" & "{ENTER}")
    Send("yes" & "{ENTER}")
    Send("crypto key generate rsa usage-keys modulus 768" & "{ENTER}")

Does anyone have any ideas?

Share this post


Link to post
Share on other sites



Well I have spent the last 3 hours trying to figure this out, I have searched the forum but found nothing relevant; what I'm trying to do is extremely simple and does not give me an error when I test using the code below:

Func InverseSM($datavlansubnet)
    $invoctettemp = StringSplit($datavlansubnet, ".")
    $invsubmask = 255 - $invoctettemp[1] & "."  & 255 - $invoctettemp[2] & "." & 255 - $invoctettemp[3] & "." & 255 - $invoctettemp[4]
    return $invsubmask
        EndFunc 
        $datavlansubnet = "255.255.255.128"
        $something = InverseSM($datavlansubnet)
        MsgBox(0,"blah",$something)

When I attempt to add the exact same function and run it in a 500 line script but I get the following error:

Array variable has incorrect number of subscripts or subscript dimension range exceeded

Note that the 500 line scripts runs fine without the function above.

The 500 line script consists of the following, there is a lot of concatenation but I believe the limit is reached on a line per line basis:

Send("enable" & "{ENTER}")
    Send("conf t" & "{ENTER}")

    Send("ip domain-name " & $domain & "{ENTER}")
    Send("hostname " & $hostname & "{ENTER}")
    Send("crypto key zeroize rsa" & "{ENTER}")
    Send("yes" & "{ENTER}")
    Send("crypto key generate rsa usage-keys modulus 768" & "{ENTER}")

Does anyone have any ideas?

There's two possibilities: The array you're trying to access is not and array,or it has not enough values for you to read.This is commonly caused by funcions failing,you should check with IsArray or UBound to avoid this kind of errors.

Share this post


Link to post
Share on other sites

When I attempt to add the exact same function and run it in a 500 line script but I get the following error:

Array variable has incorrect number of subscripts or subscript dimension range exceeded

The problem must be the data going into the varable $datavlansubnet. The string in this variable must have less than 3 dots.

When only 2 dots or less, reading $invoctettemp[4] produces the error "Array variable has incorrect number of subscripts or subscript dimension range exceeded".

Because StringSplit() always returns an array, even with no dots in this case, the IsArray() function is not needed. If there was the remotest possibility that the variable $invoctettemp might not be an array, in another case, I would definitively use the IsArray() function.

The following script may give you some ideas.

$datavlansubnet =  "255.255.255.128"
$something = InverseSM($datavlansubnet)
MsgBox(0, "blah", $something)

Func InverseSM($datavlansubnet)
    Local $invsubmask
    $invoctettemp = StringSplit($datavlansubnet, ".")
    
    ;If IsArray($invoctettemp) Then   ; not necessary here -  StringSplit() returns an array          ; 
        For $x = 1 To UBound($invoctettemp) -1  ; or For $x = 1 To $invoctettemp[0]
            $invsubmask &= 255 - $invoctettemp[$x] & "." 
        Next
        Return StringTrimRight($invsubmask,1)   
    ;Else
    ;   Return 0
    ;EndIf  
EndFunc   ;==>InverseSM

Hopefully, you have already fix the problem using danielkza's advice.

Share this post


Link to post
Share on other sites

Ok, I'm getting this error message and it makes no sense to me.

I basically have a function like this:

Function Fun($x = 0)
   If $x = 0 Then
      MsgBox(1,'dbg',$CalibIndex & ',' & $Keys[$CalibIndex])
      $idx = $Keys[$CalibIndex]
      
      ... more stuff stuff
   EndIf
EndFunc

I'm getting the error on the : $idx = $Keys[$CalibIndex] line, even though the Message Box displays the correct value. Even stranger, If i copy the code and put it at the entry point in the script, it displays the correct value with no error. I have no idea what's going on.

Share this post


Link to post
Share on other sites

Ok, I'm getting this error message and it makes no sense to me.

I basically have a function like this:

Function Fun($x = 0)
   If $x = 0 Then
      MsgBox(1,'dbg',$CalibIndex & ',' & $Keys[$CalibIndex])
      $idx = $Keys[$CalibIndex]
      
      ... more stuff stuff
   EndIf
EndFunc

I'm getting the error on the : $idx = $Keys[$CalibIndex] line, even though the Message Box displays the correct value. Even stranger, If i copy the code and put it at the entry point in the script, it displays the correct value with no error. I have no idea what's going on.

Nobody can run your reproducer script. There is no call to Fun(), functions are declared with 'Func" not 'Function', and you have not defined the Globals $CalibIndex and $Keys with values that produce the error. This runs fine:
Global $CalibIndex = 1, $Keys[3] = [0, 1, 2]

Fun()

Func Fun($x = 0)
   If $x = 0 Then
      MsgBox(1,'dbg',$CalibIndex & ',' & $Keys[$CalibIndex])
      $idx = $Keys[$CalibIndex]
      MsgBox(64, "Result", "$idx = " & $idx)
   EndIf
EndFunc

Can you change the above code to make it reproduce your problem?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Array variable has incorrect number of subscripts or subscript dimension range exceeded

I had the same error and spent countless hours examining my code.

It turns out that "Array variable has incorrect number of subscripts or blah, blah" happens when the data your code is working on returns an error, not found, or something to that effect. It is not your code, it is the data you need to look at.

Make sure all the data you are using has no errors (I don't know, formatting, number of characters, or whatever you are using to get a result) and you will probably not have the "Array variable has incorrect number of subscripts or blah, blah" error.

Share this post


Link to post
Share on other sites

I had the same error and spent countless hours examining my code.

It turns out that "Array variable has incorrect number of subscripts or blah, blah" happens when the data your code is working on returns an error, not found, or something to that effect. It is not your code, it is the data you need to look at.

Make sure all the data you are using has no errors (I don't know, formatting, number of characters, or whatever you are using to get a result) and you will probably not have the "Array variable has incorrect number of subscripts or blah, blah" error.

This is really terrible...

When I code:

_ArrayDisplay($aTableData)

$aTableData can be displayed perfectly.

but

_FileWriteFromArray($hFile, $aTableData, 1)

fails to accomplish.

So how to automate/simulate the "Copy Selected" to achieve File Write function?

Share this post


Link to post
Share on other sites

This is really terrible...

When I code:

_ArrayDisplay($aTableData)

$aTableData can be displayed perfectly.

but

_FileWriteFromArray($hFile, $aTableData, 1)

fails to accomplish.

So how to automate/simulate the "Copy Selected" to achieve File Write function?

Not sure why you resurrect this old topic, but you have to be more explicit about what your problem is for us to be able to help you.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                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

#9 ·  Posted (edited)

Not sure why you resurrect this old topic, but you have to be more explicit about what your problem is for us to be able to help you.

Jos

Ok, these are the executable codes that fail to save the table but succeed to display. Thanks for your test in advance~

#include <IE.au3>

#include <Array.au3>

#include <File.au3>

$dir = "C:\";

$murl = "http://tubic.tju.edu.cn/deg/"

$qurl = "query.php?selfield=os&term=coli"

$purl = "&page="

$oIE = _IECreate ()

_IELoadWait ($oIE)

_IENavigate ($oIE, $murl & $qurl)

$sFile = $dir & "\DEG_DB.txt"

; Open file and append second array

$hFile = FileOpen($sFile, 1) ; 1 = append

_IENavigate ($oIE, $murl & $qurl & $purl & "1")

_IELoadWait ($oIE)

$oTable = _IETableGetCollection ($oIE, 2)

$aTableData = _IETableWriteToArray ($oTable, True)

_ArrayDisplay($aTableData)

_FileWriteFromArray($hFile, $aTableData, 1)

FileClose($hFile)

Edited by cwem

Share this post


Link to post
Share on other sites

Did you run this script yourself before posting as I am getting an error on $i not being declared?

Sorry I simplified the codes for easy understanding and now it's fixed to number 1 in my previous post

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

_IETableWriteToArray returns a 2 dimentional Array so you cannot use _FileWriteFromArray() for that as it doesn't support it.

You will have to create your own code to write the results to the file.

Something like this should do it. :P

#include <IE.au3>
#include <Array.au3>
#include <File.au3>

;~ $dir = "C:";
$dir = @ScriptDir
$murl = "http://tubic.tju.edu.cn/deg/"
$qurl = "query.php?selfield=os&term=coli"
$purl = "&page="

$oIE = _IECreate($murl & $qurl & $purl & "1", 1)
_IELoadWait($oIE)
$sFile = $dir & "DEG_DB.txt"
; Open file and append second array
$hFile = FileOpen($sFile, 1); 1 = append
$oTable = _IETableGetCollection($oIE, 2)
$aTableData = _IETableWriteToArray($oTable, True)
_ArrayDisplay($aTableData)
For $x = 1 To UBound($aTableData) - 1
    For $y = 1 To UBound($aTableData,2) - 1
        If $y > 1 Then FileWrite($hFile, ";")
        FileWrite($hFile, $aTableData[$x][$y])
    Next
    FileWrite($hFile,@crlf)
Next
FileClose($hFile)
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                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

Thanks it works!

How to print character "tab"? semi-colon is not a good choice to delimit data...

And in fact what part of Help should I look for in order to locate something like

"\t, \n" etc in C, Perl and other programming languages?

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Thanks it works!

How to print character "tab"? semi-colon is not a good choice to delimit data...

And in fact what part of Help should I look for in order to locate something like

"\t, \n" etc in C, Perl and other programming languages?

What did the helpfile search turn up with ? :P

If $y > 1 Then FileWrite($hFile, @Tab)
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                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

What did the helpfile search turn up with ? :unsure:

If $y > 1 Then FileWrite($hFile, @Tab)
It gives many results but somehow i manage to identify it's from marco. "@" is the clue :P

Share this post


Link to post
Share on other sites

For $x = 1 To UBound($aTableData) - 1

For $y = 1 To UBound($aTableData,2) - 1

If $y > 1 Then FileWrite($hFile, ";")

FileWrite($hFile, $aTableData[$x][$y])

Next

FileWrite($hFile,@crlf)

Next

FileClose($hFile)

In order to print it as a "row-by-row" manner instead I modify your codes as:

For $y = 1 To UBound($aTableData,2) - 1

For $x = $head To UBound($aTableData) - 1

If $x > 1 Then FileWrite($hFile, @Tab)

FileWrite($hFile, $aTableData[$x][$y])

Next

FileWrite($hFile,@crlf)

Next

Would you please tell me what is the problem that makes a tab-delimited result fails to generate? I only get rows of data clustering together instead of being tab-delimited.

thx once again~

Share this post


Link to post
Share on other sites

Does $x happen to be greater than 1?

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