Sign in to follow this  
Followers 0
RagnaroktA

Help! Array error...

13 posts in this topic

Error:

Line 25 (File "C:\DevLib\Tools\DomainView\Subnet.au3"):

$netmaskdec = ($netmaskarray[1] * 16777216) + ($netmaskarray[2] * 65536) + ($netmaskarray[3] * 256 + $netmaskarray[4]
$netmaskdec = ($netmaskarray[1] * 16777216) + (^ERROR

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

Anyone know what this means or how to fix it?


Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

Share this post


Link to post
Share on other sites



Did you Dim it?

Dim $netmaskarray[50] ; don't know how many your using so I put 50


[center]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.[/center]

Share this post


Link to post
Share on other sites

Did you Dim it?

Dim $netmaskarray[50] ; don't know how many your using so I put 50

Sure did, there's only 4. Below is the whole function...

Func _Subnet($sIp, $sNetmask)
    Dim $netmaskbinary
    Dim $netmaskarray[4]
    Dim $subnetaddarray[5]
    Dim $invmaskarray[5]
    Dim $broadcastaddarray[5]
    Dim $sSubnetinfo[7]
    Dim $subnetadd
    Dim $invmask
    Dim $broadcastadd

; Reads IP and Netmask to an array
        $iparray = StringSplit($sIp, ".")
        $netmaskarray = StringSplit($sNetmask, ".")
    
; Validates IP address
        For $i = 1 To 4
            If Number($iparray[$i]) < 0 Or Number($iparray[$i]) > 255 Then
                SetError(1)
                Return (-1)
            EndIf
        Next
    
; Converts netmask into a decimal 
        $netmaskdec = ($netmaskarray[1] * 16777216) + ($netmaskarray[2] * 65536) + ($netmaskarray[3] * 256) + $netmaskarray[4]
    
; Converts decimal netmask into binary (ex. 11111111111111111100000000000000)
        While $netmaskdec <> 0
            $binmod = Mod($netmaskdec, 2)
            $netmaskbinary = $binmod & $netmaskbinary
            $netmaskdec = Int($netmaskdec / 2)
        WEnd
    
; Determines the "slash" value of the netmask
        $maskslash = StringInStr($netmaskbinary, "0", 1) - 1
    
; Validates the "slash" value and netmask value
        If StringInStr(StringRight($netmaskbinary, 32 - $maskslash), "1") Then
            If $netmaskarray[4] = "255" Then
                $maskslash = 32
            Else
                SetError(1)
                Return (-1)
            EndIf
        EndIf
    
; Creates arrays conatining subnet address, wilcard, and broadcast addresses
        For $i = 1 To $iparray[0]
            $subnetaddarray[$i] = BitAND($iparray[$i], $netmaskarray[$i])
            $invmaskarray[$i] = BitNOT($netmaskarray[$i] - 256)
            $broadcastaddarray[$i] = BitOR($subnetaddarray[$i], $invmaskarray[$i])
        Next
    
; Creates strings conatining subnet address, wilcard, and broadcast addresses
        $subnetadd = $subnetaddarray[1] & "." & $subnetaddarray[2] & "." & $subnetaddarray[3] & "." &$subnetaddarray[4]
        $invmask = $invmaskarray[1] & "." & $invmaskarray[2] & "." & $invmaskarray[3] & "." & $invmaskarray[4]
        $broadcastadd = $broadcastaddarray[1] & "." & $broadcastaddarray[2] & "." & $broadcastaddarray[3] & "." & $broadcastaddarray[4]
    
        If $maskslash = 32 Then
            $iprange = $iparray[1] & "." & $iparray[2] & "." & $iparray[3] & "." & $iparray[4]
            $hosts = 1
        Else
        ; Determines the IP range for this subnet
                $iprange = $subnetaddarray[1] & "." & $subnetaddarray[2] & "." & $subnetaddarray[3] & "." & $subnetaddarray[4] + 1 & _
                "-" & $broadcastaddarray[1] & "." & $broadcastaddarray[2] & "." & $broadcastaddarray[3] & "." & $broadcastaddarray[4] - 1
        ; Calculates number of available hosts on this subnet
                $hosts = ($invmaskarray[4] + 1) * ($invmaskarray[3] + 1) * ($invmaskarray[2] + 1) * ($invmaskarray[1] + 1) - 2
        EndIf
    
        $sSubnetinfo[1] = $subnetadd
        $sSubnetinfo[2] = $broadcastadd
        $sSubnetinfo[3] = $invmask
        $sSubnetinfo[4] = $iprange
        $sSubnetinfo[5] = $hosts
        $sSubnetinfo[6] = $maskslash
        
        Return ($sSubnetinfo)
EndFunc

Func _SameSub($sIp, $sSubadd, $sBroadadd)
    Dim $iparray[5]
    Dim $subaddarray[5]
    Dim $broadaddarray[5]
    
    $iparray = StringSplit($sIp, ".")
    $subaddarray = StringSplit($sSubadd, ".")
    $broadaddarray = StringSplit($sBroadadd, ".")
    
    For $i = 1 To 4
        If Number($iparray[$i]) < 0 Or Number($iparray[$i]) > 255 Then
            SetError(1)
            Return (-1)
        EndIf
        If Number($subaddarray[$i]) < 0 Or Number($subaddarray[$i]) > 255 Then
            SetError(1)
            Return (-2)
        EndIf
        If Number($broadaddarray[$i]) < 0 Or Number($broadaddarray[$i]) > 255 Then
            SetError(1)
            Return (-3)
        EndIf
    Next
    
    $ipint = ($iparray[1] * 16777216) + ($iparray[2] * 65536) + ($iparray[3] * 256) + $iparray[4]
    $subaddint = ($subaddarray[1] * 16777216) + ($subaddarray[2] * 65536) + ($subaddarray[3] * 256) + $subaddarray[4]
    $broadaddint = ($broadaddarray[1] * 16777216) + ($broadaddarray[2] * 65536) + ($broadaddarray[3] * 256) + $broadaddarray[4]
    
    If $ipint > $subaddint And $ipint < $broadaddint Then
        Return (1)
    Else
        Return (0)
    EndIf
EndFunc

Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well you're using 4 $netmaskarray's , and you Dim $netmaskarray[4] (they start with "0") , also, did you use #include <array.au3> , you don't need it for my example... but may help if your going to use array's B) .

I don't know what values your looking for, but this is an example all the same:

#include <array.au3>

Dim $netmaskarray[5]

$netmaskarray[1] = 1
$netmaskarray[2] = 2
$netmaskarray[3] = 3
$netmaskarray[4] = 4

$netmaskdec = ($netmaskarray[1] * 16777216) + ($netmaskarray[2] * 65536) + ($netmaskarray[3] * 256) + $netmaskarray[4]

MsgBox(0, "", $netmaskdec)

Also, I don't see where you defined the array... [1] / [2] etc...

Edited by ronsrules

[center]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.[/center]

Share this post


Link to post
Share on other sites

Well you're using 4 $netmaskarray's , and you Dim $netmaskarray[4] (they start with "0") , also, did you use #include <array.au3> , you don't need it for my example... but may help if your going to use array's B) .

I don't know what values your looking for, but this is an example all the same:

#include <array.au3>

Dim $netmaskarray[5]

$netmaskarray[1] = 1
$netmaskarray[2] = 2
$netmaskarray[3] = 3
$netmaskarray[4] = 4

$netmaskdec = ($netmaskarray[1] * 16777216) + ($netmaskarray[2] * 65536) + ($netmaskarray[3] * 256) + $netmaskarray[4]

MsgBox(0, "", $netmaskdec)

Also, I don't see where you defined the array... [1] / [2] etc...

This is a part of the Domain PC Info script in the following thread:

http://www.autoitscript.com/forum/index.php?showtopic=6850

If you look at all of the code, it doesnt look like a single array begins with 0. Confused me, but everyone else seemed to be alright with it. If arrays dont start with 0 will it create a problem? I tried modifying this array to use 0-3 but it did the same thing...

The array is defined here:

$netmaskarray = StringSplit($sNetmask, ".")

What do you think?


Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Use...

Dim $netmaskarray[5]

Edit:

Let me try to explain (I'm not so good with arrays either, just trying to help).

The array starts at "0" count, you're not using $netmaskarray[0], you started with [1]. But it still counts. So you go to [0] [1] [2] [3] [4] = [5].

Also, I never really looked at the script (sorry..), but...

$netmaskarray = StringSplit($sNetmask, ".") this isn't an array, it's a simply a variable.

Look at _ArrayCreate() and or For / Next (to creat your own) in help file.

Edited by ronsrules

[center]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.[/center]

Share this post


Link to post
Share on other sites

Use...

Dim $netmaskarray[5]

Edit:

Let me try to explain (I'm not so good with arrays either, just trying to help).

The array starts at "0" count, you're not using $netmaskarray[0], you started with [1]. But it still counts. So you go to [0] [1] [2] [3] [4] = [5].

Also, I never really looked at the script (sorry..), but...

$netmaskarray = StringSplit($sNetmask, ".") this isn't an array, it's a simply a variable.

Look at _ArrayCreate() and or For / Next (to creat your own) in help file.

Ack, sorry... wasnt even paying attention. Yeah, that's just a variable. $sNetmask is fed to the function from another script. I tried changing it to Dim $netmaskarray[5] and still got the same. Checked the help file, to no avail.

Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I notice in your code that you are doing the same thing with both $iparray and $netmaskarray... yet you only mention getting an error for $netmaskarray

The only difference I see is that you are not doing a Dim for $iparray

Have you tried not declaring $netmaskarray? the help file omits this step in the example for StringSplit()

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

I notice in your code that you are doing the same thing with both $iparray and $netmaskarray... yet you only mention getting an error for $netmaskarray

The only difference I see is that you are not doing a Dim for $iparray

Have you tried not declaring $netmaskarray? the help file omits this step in the example for StringSplit()

Yeah, it started out that way. Still got the same error, and always in the same place.


Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Weird.. This code works for me and it seams to be doing the same thing your script is having problems with:

#include <array.au3>
Dim $netmaskarray[5]
    
$sIp = InputBox("","enter IP","10.100.111.1")
$sNetmask = InputBox("","enter Subnet Mask","255.255.255.0")

; Reads IP and Netmask to an array
$iparray = StringSplit($sIp, ".")
$netmaskarray = StringSplit($sNetmask, ".")

_ArrayDisplay($iparray,"")
_ArrayDisplay($netmaskarray,"")

$netmaskdec = ($netmaskarray[1] * 16777216) + ($netmaskarray[2] * 65536) + ($netmaskarray[3] * 256) + $netmaskarray[4]
MsgBox(0,"$netmaskdec= ",$netmaskdec)
Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Just had a thought... are you sure you are passing the required information to your function?


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Error:

Line 25 (File "C:\DevLib\Tools\DomainView\Subnet.au3"):

$netmaskdec = ($netmaskarray[1] * 16777216) + ($netmaskarray[2] * 65536) + ($netmaskarray[3] * 256 + $netmaskarray[4]
$netmaskdec = ($netmaskarray[1] * 16777216) + (^ERROR

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

Anyone know what this means or how to fix it?

you are missing the closing ')' bracket at the end of the line:

$netmaskdec = ($netmaskarray[1] * 16777216) + ($netmaskarray[2] * 65536) + ($netmaskarray[3] * 256 + $netmaskarray[4])  ;<<------ ')' missing in your code.

HardCopy


Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Just had a thought... are you sure you are passing the required information to your function?

Pretty sure, but I'll check real quick...

Edit: Okay so I figured it out. The script looks for the IP address from the network card, but will only work wired, not wirelessly. I was connected wirelessly at the time.

Edited by RagnaroktA

Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

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