Jump to content

Im getting an error with an array


Recommended Posts

Global $Number = 4
Global $IPAddress1 = "192.168.1.37"
Global $IPAddress2 = "192.168.1.40"
Global $IPAddress3 = "192.168.1.41"
Global $IPAddress4 = "192.168.1.47"
Global $IPArray[$Number + 1] = [ $Number, $IPAddress1, $IPAddress2, $IPAddress3, $IPAddress4 ]
Global $Timer = TimerInit()

While 1
    If $TimerD >= 1800000 Then;30 minutes restart vnc
        CloseVNC()
        Sleep(1000)
        StartVNC()
        Sleep(1000)
        $Timer = TimerInit()
    EndIf
WEnd

Func StartVNC()
    Local $VNCXPos1 = 77;XPosition of Opened VNC Window
    For $i = 1 To $Number
        Run(@ProgramFilesDir & "\RealVnc\VNC Viewer\vncviewer.exe")
        WinWait("VNC Viewer")
        Send($IPArray[$i]);<----- Here is where I'm getting an error
        Sleep(50)
        Send("{ENTER}")
        Sleep(1000)
        Send("Password" & "{ENTER}")
        Sleep(200)
        MouseClickDrag("Left", 715, 345, $VNCXPos1, 11, 10)
        $VNCXPos1 += 320
    Next
EndFunc

I have a loop where I run 4 vnc windows and when I start the script it works fine but it appears that when it attempts to startVNC() after 30 minutes I get an error on the Send($IPArray[$i])

The console outputs this:

"C:\Documents and Settings\user\Desktop\Test.au3" (243) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$IPTemp1 = $IPArray[$i]
$IPTemp1 = ^ ERROR

and the script crashes. What am I missing? Using message box to see the value of $IPArray[$i] only shows the 4 ip addresses with no issues.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Func CloseVNC()
    For $g = 1 To $Number; Close all instances of VNC Viewer at start of script
        ProcessClose("vncviewer.exe")
        Sleep(500)
    Next
EndFunc   ;==>CloseVNC

@Kylomas I tried to set $IPArray[$i] to a variable then call the variable and I got the same message. Forgot to modify the output.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

"C:Documents and SettingsuserDesktoptest.au3" (245) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
Send($IPArray[$i])
Send(^ ERROR

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Did you post the whole code ? sending to Notepad with the same  code produces no error

Global $Number = 4
Global $IPAddress1 = "192.168.1.37"
Global $IPAddress2 = "192.168.1.40"
Global $IPAddress3 = "192.168.1.41"
Global $IPAddress4 = "192.168.1.47"
Global $IPArray[$Number + 1] = [ $Number, $IPAddress1, $IPAddress2, $IPAddress3, $IPAddress4 ]
Global $Timer = TimerInit()

Sleep(3000)  ; delay to activate a blank notepad
While 1
    If TimerDiff($Timer) >= 2000 Then
        StartVNC()
        Sleep(1000)
        $Timer = TimerInit()
    EndIf
WEnd

Func StartVNC()
    For $i = 1 To $Number
        Send($IPArray[$i])
        Sleep(50)
    Next
EndFunc
Link to comment
Share on other sites

It isn't being changed in the script but I am not sure about redimmed. I only define the array in the beginning of the script. It is called to open vnc only. I added a timerinit and timerdiff to automatically restart the vnc windows after 30 minutes and that's when it started happening. It works correctly the first time and when it restarts vnc after 30 minutes the first time thats when it fails.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Ditto mikell.  Here is your code changed to use Notepad instead of vnc...

Global $Number = 4
Global $IPAddress1 = "192.168.1.37"
Global $IPAddress2 = "192.168.1.40"
Global $IPAddress3 = "192.168.1.41"
Global $IPAddress4 = "192.168.1.47"
Global $IPArray[$Number + 1] = [ $Number, $IPAddress1, $IPAddress2, $IPAddress3, $IPAddress4 ]
Global $Timer = TimerInit()

local $cycle_time = 1000 * 10
ConsoleWrite($cycle_time & @CRLF)

While 1
    If timerdiff($Timer) >=  $cycle_time Then   ; <---- use timerdiff() to get milleseconds since last timerinit()
        CloseVNC()
        Sleep(1000)
        StartVNC()
        Sleep(1000)
        $Timer = TimerInit()
    EndIf
WEnd

Func StartVNC()
    Local $VNCXPos1 = 77;XPosition of Opened VNC Window
    For $i = 1 To $Number
        Run("notepad.exe")
        WinWait("Untitled - Notepad")
        send($IPArray[$i])  ;<----- Here is where I'm getting an error
        Sleep(50)
        Send("{ENTER}")
        Sleep(1000)
        Send("Password" & "{ENTER}")
        Sleep(200)
        MouseClickDrag("Left", 715, 345, $VNCXPos1, 11, 10)
        $VNCXPos1 += 320
    Next
EndFunc

Func CloseVNC()
    For $g = 1 To $Number; Close all instances of VNC Viewer at start of script
        ProcessClose("notepad.exe")
        Sleep(500)
    Next
EndFunc   ;==>CloseVNC

kylomas

edit: duration changed to re-cycle every 10 seconds

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...