Jump to content

Subscript used on non-accessible variable


Recommended Posts

Hello,

I am looking for a small bit of help.  I'm trying to get my script working in a Chrome window.  If I remove the resize code, my script will work fine and click the button that I want it to.  What I am trying to do is get it work if the window changes sizes or if the computer has a different resolution then what I created this on.  There probably is an easier way to do this but this is what I found by searching through the forums. 

When I run the code below and use my hotkey, I get this error.  Thanks in advance!!!!

"C:\Users\BaDvs3viL\Documents\asdasd.au3" (11) : ==> Subscript used on non-accessible variable.:
$return[0] = $size[1] * ($_x / $size[0])
$return[0] = $size^ ERROR

Here is my script.

HotKeySet("{1}", "Source1")

Func MsClick($tittle, $text, $controlid, $clickType, $clicks = 1, $x = 1, $y = 1)
    $coord = UiRatio($x, $y)
    ControlClick($tittle, $text, $controlid, $clickType, $clicks, $coord[0], $coord[1])
EndFunc   ;==>MsClick

Func UiRatio($_x, $_y)
    Dim $return[2]
    $size = WinGetClientSize("[CLASS:STUDIO | Producer - Google Chrome]") ; Must set so we can get windows' size
    $return[0] = $size[1] * ($_x / $size[0])
    $return[1] = $size[1] * ($_y / $size[1])
    Return $return
EndFunc   ;==>UiRatio

While 1
Sleep(100)
WEnd

Func Source1()
Opt("MouseCoordMode", 2)
MsClick("STUDIO | Producer - Google Chrome", "", "", "left", 1, 1282, 627)
MsClick("STUDIO | Producer - Google Chrome", "", "", "left", 1, 964, 312)

EndFunc

 

Link to comment
Share on other sites

It seems like WinGetClientSize can't find the window, probably because you're trying to look for the class of the window and its title at the same time. Pick one.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You sir are correct on that.  I tested out the code using notepad instead and it worked.  I then switched back over to Chrome and now it clicks the button fine but it does not once I resize the window.  Thoughts?

 

HotKeySet("{1}", "Source1")

Func MsClick($tittle, $text, $controlid, $clickType, $clicks = 1, $x = 1, $y = 1)
    $coord = UiRatio($x, $y)
    ControlClick($tittle, $text, $controlid, $clickType, $clicks, $coord[0], $coord[1])
EndFunc   ;==>MsClick

Func UiRatio($_x, $_y)
    Dim $return[2]
    $size = WinGetClientSize("STUDIO | Producer - Google Chrome") ; Must set so we can get windows' size
    $return[0] = $size[0] * ($_x / $size[0])
    $return[1] = $size[1] * ($_y / $size[1])
    Return $return
EndFunc   ;==>UiRatio

While 1
Sleep(100)
WEnd

Func Source1()
Opt("MouseCoordMode", 2)
MsClick("STUDIO | Producer - Google Chrome", "", "", "left", 1, 1283, 628)
;MsClick("STUDIO | Producer - Google Chrome", "", "", "left", 1, 964, 312)

EndFunc

 

Link to comment
Share on other sites

21 minutes ago, badvs3vil said:

  Thoughts?

Do some error checking. Check to see if there's an error returned from WinGetClientSize before trying to return the array that isn't there.  You should do some error checking in MsClick as well in case the UIRatio function fails to find the window as well.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Every function should return either a valid return or sets the @error.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

9 hours ago, badvs3vil said:

@BrewManNH,

Thank you sir.  I am obvisly super new to this.  Can you give me any tips on adding in error checking?  I am looking at the documentation now.

Again, thank you.

HotKeySet("{1}", "Source1")

Func MsClick($tittle, $text, $controlid, $clickType, $clicks = 1, $x = 1, $y = 1)
    $coord = UiRatio($x, $y)
    If IsArray($coord) Then
        ControlClick($tittle, $text, $controlid, $clickType, $clicks, $coord[0], $coord[1])
    Else
        MsgBox(1, "Error", "UIRatio() didn't return an Array")
    EndIf
EndFunc   ;==>MsClick

Func UiRatio($_x, $_y)
    Dim $return[2]
    $size = WinGetClientSize("STUDIO | Producer - Google Chrome") ; Must set so we can get windows' size
    If @error Then ; If @error >= 1 then return
        Return
    Else
        $return[0] = $size[0] * ($_x / $size[0])
        $return[1] = $size[1] * ($_y / $size[1])
    EndIf
    Return $return
EndFunc   ;==>UiRatio

While 1
Sleep(100)
WEnd

Func Source1()
Opt("MouseCoordMode", 2)
MsClick("STUDIO | Producer - Google Chrome", "", "", "left", 1, 1283, 628)
;MsClick("STUDIO | Producer - Google Chrome", "", "", "left", 1, 964, 312)

EndFunc

 

When i'm inserting the code on the forum the formating doesn't look good, but if you paste it into Scite It should be fine

 

Edit : or you can be a better scripter than I am and follow BrewManNH recommandations and use SetError() to set your own error flag that you'll check after UiRatio() Returns

Edited by Jojo-OP2
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...