Jump to content

Issue Subscript used with non-Array


Recommended Posts

hello, im fairly new, i get this error when i click on an icon on my desktop. This script is supposed to allow drag and drop, so that i can drop an executable to it, and it will get it's icon, then display it, afterwards i can drag the icon around, but with the "move control with mouse" function , it fails when i click outside the script to grab an executable.

Scripts:

CtrlResizeMovenew.au3

#include <GUIConstantsEx.au3>
#include <Misc.au3>

    


Opt('MustDeclareVars', 1)
Func _CtrlResizeMove()
    Local $aCPos, $aMPos, $aMPosNew, $Num, $scriptPath, $hWnd, $aClssNmNN, $sTxt, $ClssNmNN, $iCommasNo
    Select
        Case _IsPressed("01"); Ctrl + Left mouse button to move
            Opt("MouseCoordMode", 2);1=absolute, 0=relative, 2=client
            $aMPos = MouseGetPos()
            $aClssNmNN = _CtrlGetByPos($hWnd, "", $aMPos[0], $aMPos[1], 0); uses client mouse coords
            Opt("MouseCoordMode", 1);1=absolute, 0=relative, 2=client
            $aMPos = MouseGetPos()
            If IsArray($aClssNmNN) Then $ClssNmNN = $aClssNmNN[1]
            $aCPos = ControlGetPos($hWnd, "", $ClssNmNN)
            Do
                $aMPosNew = MouseGetPos()
                ControlMove($hWnd, "", $ClssNmNN, $aCPos[0] + $aMPosNew[0] - $aMPos[0], _
                        $aCPos[1] + $aMPosNew[1] - $aMPos[1])
                Sleep(100)
            Until Not _IsPressed("01")

    EndSelect
EndFunc  ;==>_CtrlResizeMove

; From http://www.autoitscript.com/forum/index....=&showtopic=30717&view=findpos
Func _CtrlGetByPos($hWin, $sText = '', $iXPos = 0, $iYPos = 0, $iReturnType = 0)
    If IsString($hWin) Then $hWin = WinGetHandle($hWin)
    Local $sClassList = WinGetClassList($hWin), $hCtrlWnd
    Local $sSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn = ''
    For $iCount = UBound($sSplitClass) - 1 To 1 Step -1
        Local $nCount = 0
        While 1
            $nCount += 1
            Local $aCPos = ControlGetPos($hWin, $sText, $sSplitClass[$iCount] & $nCount)
            If @error Then ExitLoop
            If $iXPos >= $aCPos[0] And $iXPos <= ($aCPos[0] + $aCPos[2]) _
                    And $iYPos >= $aCPos[1] And $iYPos <= ($aCPos[1] + $aCPos[3]) Then
                If $sSplitClass[$iCount] <> '' And Not $iReturnType Then
                    Local $aClassNN[2] = [2, $sSplitClass[$iCount] & $nCount]
                    Return $aClassNN
                EndIf
                If $sSplitClass[$iCount] <> '' And $iReturnType = 3 Then
                    $hCtrlWnd = ControlGetHandle($hWin, $sText, $sSplitClass[$iCount] & $nCount)
                    ControlFocus($hWin, $sText, $hCtrlWnd)
                    $aReturn = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hCtrlWnd)
                    If @error = 0 And $aReturn[0] <> '' Then
                        Local $aClassNN[4] = [4, $aReturn[0], $sSplitClass[$iCount] & $nCount, $hCtrlWnd]
                        Return $aClassNN
                    EndIf
                    Local $aClassNN[2] = [2, $sSplitClass[$iCount] & $nCount]
                    Return $aClassNN
                ElseIf $sSplitClass[$iCount] <> '' And $iReturnType = 2 Then
                    Return ControlGetHandle($hWin, $sText, $sSplitClass[$iCount] & $nCount)
                ElseIf $sSplitClass[$iCount] <> '' And $iReturnType = 1 Then
                    $hCtrlWnd = ControlGetHandle($hWin, $sText, $sSplitClass[$iCount] & $nCount)
                    ControlFocus($hWin, $sText, $hCtrlWnd)
                    $aReturn = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hCtrlWnd)
                    If @error = 0 And $aReturn[0] <> '' Then
                        Local $aClassNN[2] = [2, $aReturn[0]]
                        Return $aClassNN
                    EndIf
                EndIf
                Return SetError(1, 0, 0)
            EndIf
        WEnd
    Next
    Return SetError(2, 0, 0)
EndFunc  ;==>_CtrlGetByPos
;

Test.au3

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include "CtrlResizeMovenew.au3"; < ===== Inserted here (Remove when finished) ========

Local $msg
GUICreate("My Program", 320, 320, -1, -1, -1, $WS_EX_ACCEPTFILES)
;$button=GUICtrlCreateButton("drag here",10,10,300,140)
Global $button = GUICtrlCreatePic("", -1, -1, 320, 320)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()

If $msg = $GUI_EVENT_DROPPED Then
        
        
    GUICtrlSetImage($d, @GUI_DragFile, 0)
    EndIf
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
If $msg <> $GUI_EVENT_DROPPED Then _CtrlResizeMove()    
WEnd
GUIDelete()

heres the log:

C:\Documents and Settings\Mega\Desktop\EncryDecryau3\CtrlResizeMovenew.au3 (21) : ==> Subscript used with non-Array variable.:
ControlMove($hWnd, "", $ClssNmNN, $aCPos[0] + $aMPosNew[0] - $aMPos[0], $aCPos[1] + $aMPosNew[1] - $aMPos[1])
ControlMove($hWnd, "", $ClssNmNN, $aCPos^ ERROR
>Exit code: 1    Time: 12.826
Link to comment
Share on other sites

Line

...
$aCPos = ControlGetPos($hWnd, "", $ClssNmNN)
...

is causing an error because ControlGetPos() cannot obtain the size and position of the control!

You can add an error check, e.g. If @error Then Return SetError(1, 0, 0) just after the line.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 1 month later...

Line

...
$aCPos = ControlGetPos($hWnd, "", $ClssNmNN)
...

is causing an error because ControlGetPos() cannot obtain the size and position of the control!

You can add an error check, e.g. If @error Then Return SetError(1, 0, 0) just after the line.

Br,

UEZ

Thankyou, but now im having another issue; when i go to drag an executable instead of the executable icon being dragged the entire control tried to come with it, and its causing any and every single ctrl i click on to be dragged around weather its my taskbar, my desktop, anything. is there anyway to restrict this to my GUI only? or more specifically only being able to move an icon that ive dragged to the GUI, and nothing else. if you try my script youll see exaclty what im talking about, but youll have to add your error control to the script, thankyou.
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...