<SparTacuS> Posted November 29, 2004 Share Posted November 29, 2004 Hello Everyone, My first post/first script and I'm afraid it's a question already (pro'lly a no-brainer for the experienced) My script is intended to keep Media Player obviously visable if running - but this part keeps throwing a "Subscript used with nonArray variable" error. ;Dim $size[2]; ; $size = WinGetClientSize("Windows Media Player") ; ; If $size[0]<300 OR $size[1]<300 Then; WinMove("Windows Media Player", "", $xpos, $ypos, 300, 300); EndIf; As you can see i've tried both Dim-ing it and letting WinGetClientSize do it for me. Neither makes any difference. Where am I going wrong? Link to comment Share on other sites More sharing options...
Developers Jos Posted November 29, 2004 Developers Share Posted November 29, 2004 You need to test for @error = 1 because when WinGetClientSize fails it returns a 1 in stead of an Array:Failure: Returns numeric 1 and sets @error to 1 if windows is not found. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ezzetabi Posted November 29, 2004 Share Posted November 29, 2004 (edited) So Dim $size[2]; $size = WinGetClientSize("Windows Media Player") If Not @error AND ($size[0]<300 OR $size[1]<300) Then WinMove("Windows Media Player", "", $xpos, $ypos, 300, 300) EndIf Blank lines are allowed and trailing ; are not needed. Edit: small note about my If line, there is no need for a separed If for @error and size[0] since being a AND if the @error becomes false AutoIt wont even consider the last part of the test because whatever is second part result this won't alter the final result! So if there is an error size is no checked and so it gives no problem about reading the non existent array. Edited November 29, 2004 by ezzetabi Link to comment Share on other sites More sharing options...
<SparTacuS> Posted November 29, 2004 Author Share Posted November 29, 2004 Thank you v.much ezzetabi - that works perfectly. And thanks both for your swift replies. Link to comment Share on other sites More sharing options...
SlimShady Posted November 29, 2004 Share Posted November 29, 2004 (edited) You shouldn't assume everything will work as expected.You have to add error checking.Check the help file for more info.Failure: Returns numeric 1 and sets @error to 1 if windows is not found.While I fixed your code a little, here's what you do:$size = WinGetClientSize("Windows Media Player") If NOT @error Then ;If function failed then @error equals 1 so NOT @error means turn 1 into 0 and that means statement is false. ;If successful then @error equals 0 so NOT @error means turn 0 into 1 and that means statement is true. If $size[0] < 300 OR $size[1] < 300 Then WinMove("Windows Media Player", "", $xpos, $ypos, 300, 300) EndIf EndIfDamn! You're too quick for me Edited November 29, 2004 by SlimShady Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now