Jump to content

Odd Script Error


Recommended Posts

Dim $Coord[1][1]
Global $Con = False
Global $i   = 0

HotKeySet("{F3}", "Change")
HotKeySet("{F4}", "Repeat")

Func Change()
    $Con = not $Con
EndFunc

Func Repeat()
    For $n = 0 to UBound($Coord) Step 1
        MouseMove( $Coord[$n][0], $Coord[$n][1], 100 )
    Next

    MsgBox(0, "", "Done")
EndFunc

While 1
    If $Con Then
        $Coord[$i][0] = MouseGetPos(0)
        $Coord[$i][1] = MouseGetPos(1)

        $i = $i + 1
        ReDim $Coord[$i][1]
    EndIf

    Sleep(0)
WEnd

When I press F3 hotkey, the script terminates itself with such error:

C:\Users\????\Desktop\Recorder.au3 (23) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$Coord[$i][1] = MouseGetPos(1)
^ ERROR

What's the problem? Help, please.

Link to comment
Share on other sites

Dim $Coord[1][1]
Global $Con = False
Global $i   = 0

HotKeySet("{F3}", "Change")
HotKeySet("{F4}", "Repeat")

Func Change()
    $Con = not $Con
EndFunc

Func Repeat()
    For $n = 0 to UBound($Coord) Step 1
        MouseMove( $Coord[$n][0], $Coord[$n][1], 100 )
    Next

    MsgBox(0, "", "Done")
EndFunc

While 1
    If $Con Then
        $Coord[$i][0] = MouseGetPos(0)
        $Coord[$i][1] = MouseGetPos(1)

        $i = $i + 1
        ReDim $Coord[$i][1]
    EndIf

    Sleep(0)
WEnd

When I press F3 hotkey, the script terminates itself with such error:

C:\Users\????\Desktop\Recorder.au3 (23) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$Coord[$i][1] = MouseGetPos(1)
^ ERROR

What's the problem? Help, please.

The problem is as the error tells you. When the script starts $con = 0 so the assigning of $Coord doesn't happen untill the hot key makes it 1. Then the error is hown that you have only 1 element in th esecond dimension but you need 2. ([$i][0] and [$i][1])

So you need to correct your first declaration and your ReDim line.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

The problem is as the error tells you. When the script starts $con = 0 so the assigning of $Coord doesn't happen untill the hot key makes it 1. Then the error is hown that you have only 1 element in th esecond dimension but you need 2. ([$i][0] and [$i][1])

So you need to correct your first declaration and your ReDim line.

Ok, I've changed the first line from
Dim $Coord[1][1]
to
Dim $Coord[1][2]

And

ReDim $Coord[$i][1]
to
ReDim $Coord[$i][2]

But now the script terminates itself on the first assignment ($Coord[$i][0] = MouseGetPos(0)). Huh?

Edited by UrS
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...