AlanMorseDavies Posted May 4, 2010 Share Posted May 4, 2010 Hi all, I'm new here so I apologise in advance if I'm breaking any conventions, I just wanted to get some help with a script which mostly works, but occasionally throws up this error:"Error: Array variable had incorrect number of subscripts or subscript dimension range exceeded".The error occurs at line 49, and the script was compiled with v 3.3.6.1, I'm running Windows 7 Ultimate.I'm new to this, I think there's probably a better way to do what I'm attempting, unfortunately I lack the experience to work out what it is.If anyone could be help that would be fantastic. The script is below and line 49 is in a larger font:$m_amip = "C:\nextsong.txt"$m_ip = "127.0.0.1"$m_port = 9090TCPStartUp()$m_tcp = TCPConnect($m_ip,$m_port)If @error Then MsgBox(0, "FooSQ", "SqueezeCenter not responding") ExitEndIfOpt("WinTitleMatchMode", 2)$m_foo = "foobar2000"$m_lts = 19$m_f = ""$m_r = "0"$m_s = "0"$m_p = "?"$m_t = ""$m_l = "0"$m_n = ""$m_ne = ""$m_pref = ""$m_fn = ""$m_ln = "0"$m_lt=229$m_title = WinGetTitle($m_foo, "")If $m_title = "0" Then MsgBox(0, "FooSQ", "Please start Foobar") ExitEndIfTCPSend($m_tcp,"playlist clear" & @CRLF)While 1 $m_title = WinGetTitle($m_foo, "") If StringRegExp ( $m_title, $m_foo ) <> 1 Then Exit EndIf If StringRegExp ( $m_title, "Preferences" ) Then if $m_pref = "" Then MsgBox(0, "FooSQ", "Staying in Foobar Preferences a while may desynchronize FooSQ. Do a Foobar Stop/Play when finished") Endif $m_pref = "1" Else $m_pref = "" EndIf If $m_pref = "" Then $m_ln = StringLen($m_title) if $m_ln <> $m_lts Then $a_tn = StringSplit($m_title, "/") $m_fn = $a_tn[1] $m_r = $a_tn[2] $m_p = $a_tn[3] EndIf Select Case $m_ln = $m_lts AND $m_s <> "0" $m_s = "0" TCPSend($m_tcp,"stop" & @CRLF & "playlist clear" & @CRLF) Case $m_ln <> $m_lts AND $m_s = "0" $m_s = "1" $m_f = $m_fn $m_sq = StringReplace(StringReplace($m_fn, "\", "/"), " ", "%20") TCPSend($m_tcp, "playlist play " & $m_sq & @CRLF) Case $m_ln <> $m_lts AND $m_s = "1" if $m_p = "1" Then $m_s = "2" TCPSend($m_tcp,"pause 1" & @CRLF) Else if $m_f <> $m_fn Then $m_sq = StringReplace(StringReplace($m_fn, "\", "/"), " ", "%20") if $m_t = "0" Then if $m_fn <> $m_n Then TCPSend($m_tcp,"playlist play " & $m_sq & @CRLF) Endif Else TCPSend($m_tcp,"playlist play " & $m_sq & @CRLF) Endif $m_t = "" $m_ne = "" Else if $m_r = "11" OR $m_r = "10" Then if $m_ne = "" Then $m_amips = FileOpen($m_amip, 0) If $m_amips = -1 Then MsgBox(0, "FooSQ", "AMIP next song file not found") Exit EndIf $m_n = FileReadLine($m_amip) FileClose($m_amip) $m_sq = StringReplace(StringReplace($m_n, "\", "/"), " ", "%20") TCPSend($m_tcp,"playlist insert " & $m_sq & @CRLF) $m_ne = "1" Endif Endif if $m_r = "0" OR $m_r = "1" Then $m_t = "0" Endif Endif $m_f = $m_fn EndIf Case $m_ln <> $m_lts AND $m_s = "2" if $m_p = "?" Then $m_s = "1" TCPSend($m_tcp, "pause 0" & @CRLF) EndIf EndSelect Endif sleep($m_lt)WEndExit Link to comment Share on other sites More sharing options...
Juvigy Posted May 4, 2010 Share Posted May 4, 2010 StringRegExp returns an array i think. That is why you get the error - check the help file Link to comment Share on other sites More sharing options...
MHz Posted May 4, 2010 Share Posted May 4, 2010 "Error: Array variable had incorrect number of subscripts or subscript dimension range exceeded". The error occurs at line 49, and the script was compiled with v 3.3.6.1, I'm running Windows 7 Ultimate. Welcome, I note the script as compiled and a line was given. A compiled script has comments, empty lines etc. removed when compilation happens. If you remove all empty lines from your script then the error would happen on this line shown below. $m_r = $a_tn[2] This is a line using the array returned from StringSplit(). You should check the value in $a_tn[0] or use Ubound($a_tn) to find out how many elements exist in the array. Obviously, $a_tn[2] is a non-existent element of the array so you get an error. This example may help to show what is happening. ; check variables $m_title = '1/2/3' ;~ $m_title = '1/2' ; uncomment to see difference $m_lts = 'different' ;... $m_ln = StringLen($m_title) if $m_ln <> $m_lts Then $a_tn = StringSplit($m_title, "/") If $a_tn[0] = 3 Then $m_fn = $a_tn[1] $m_r = $a_tn[2] $m_p = $a_tn[3] MsgBox(0, '$a_tn[0]', $a_tn[0] & ' elements to use. OK') Else MsgBox(0, '$a_tn[0]', $a_tn[0] & ' elements only to use') EndIf EndIf Link to comment Share on other sites More sharing options...
GEOSoft Posted May 4, 2010 Share Posted May 4, 2010 (edited) StringRegExp returns an array i think. That is why you get the error - check the help file Not when it's used with either no flag or the flag is set to 0. It will return 1 if valid or 0 if not valid It returns an array only if the flag is set to 2, 3, or 4. Of course using an SRE in this case was overkill anyway This would have done the same thing. $m_title = WinGetTitle($m_foo, "") If NOT StringInStr( $m_title, $m_foo ) Then Exit EndIf Edit: In fact, I don't see any good reason for that bit of code being there anyway because it should always return 1 Edited May 4, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
AlanMorseDavies Posted May 6, 2010 Author Share Posted May 6, 2010 Fixed! Brilliant, thank you both for your help on this, I really appreciate it. Link to comment Share on other sites More sharing options...
AlanMorseDavies Posted May 6, 2010 Author Share Posted May 6, 2010 (edited) The problem was indeed with an incorrect number of array elements being returned from StringSplit. This was caused by WinGetTitle not returning data from the correct window. I fixed it by setting WinTitleMatch to 3 (exact match), and substituting the WinGetTitle string search for the window classname. Before: $m_title = WinGetTitle("foobar2000", "") After: $m_title = WinGetTitle("[CLASS:{97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}]", "") Thanks to you both again. Edited May 6, 2010 by AlanMorseDavies Link to comment Share on other sites More sharing options...
Fizbin Posted March 22, 2015 Share Posted March 22, 2015 This script is still floating around and being used today. Yes I'm dusting off a 5 year old thread. The OP posted this script on the Slim Devices forum a few years ago and he has since made some mods to it. He is no longer supporting it but he doesn't mind people using it or changing it. It hasn't changed much since his last update. This script allows one to control their Squeezebox Touch with Foobar2000. If you just sit back and let it play, it works fine. But it you start skipping or seeking tracks a lot, as I tend to do, the following line can still throw an error... $m_r = $a_tn[2] Since I'm not a programmer, I was wondering if any kind person, with a little free time, could help pinpoint the problem. I think "MHz", above, was onto the issue but I'm a little unsure as to what he was getting at. I'll post the entire script below. Thanks! expandcollapse popup$m_ip = "127.0.0.1" $m_port = 9090 $m_playerid = "00:04:25:22:e2:60" $m_fooexe = "C:\Program Files (x86)\foobar2000\foobar2000.exe" $m_amip = "D:\MUSIC\nextsong.txt" $m_fooh = "[CLASS:{E7076D1C-A7BF-4f39-B771-BCBE88F2A2A8}]" $m_naspath = "D:\MUSIC\" $m_f = "" $m_r = "0" $m_s = "0" $m_p = "?" $m_t = "" $m_n = "" $m_ne = "" $m_fn = "" $m_sq = "" $m_title = "" $m_idle = 0 $m_ro = "0" $m_seek = 0 $m_elt = "" $m_seekt = 1 $m_0seek = 0 SplashTextOn( "FooSQ", "Loading...", 250, 50) Run($m_fooexe, "", @SW_MAXIMIZE) WinWait($m_fooh, "", 60) $m_fooha = WinGetHandle($m_fooh) TCPStartup() SplashOff() $m_tcp = TCPConnect($m_ip, $m_port) if @error Then MsgBox(1, "FooSQ", "Not working") Else SplashTextOn( "FooSQ", "Connected!", 250, 50) SplashOff() EndIf While WinExists($m_fooha) $m_title = WinGetTitle($m_fooha) If StringRegExp($m_title, "foobar2000") Then $m_idle = 1 Else $m_idle = 0 EndIf If $m_idle = 0 And $m_title <> "" Then $a_tn = StringSplit($m_title, "/") $m_fn = $a_tn[1] $m_r = $a_tn[2] $m_p = $a_tn[3] $m_elt = $a_tn[4] if number($m_seekt) > 0 AND $m_0seek = 0 Then $m_seekv = number($m_r) - number($m_ro) if abs($m_seekv) > $m_seekt AND $m_ro <> "0" AND $m_f = $m_fn Then $m_seek = 1 Endif Endif $m_ro = $m_r if $m_0seek > 0 then $m_0seek = $m_0seek -1 endif Else $m_0seek = 50 EndIf Select Case $m_idle = 1 And $m_s <> "0" $m_s = "0" TCPSend($m_tcp,$m_playerid & " stop" & @CRLF & " playlist clear " & @CRLF) Case $m_idle = 0 And $m_s = "0" $m_s = "1" $m_f = $m_fn $m_sq = StringReplace(StringReplace(StringReplace($m_fn, "\", "/"), " ", "%20"), $m_NASPath, "") TCPSend($m_tcp,$m_playerid & " playlist play " & $m_sq & @CRLF) Case $m_idle = 0 AND $m_s = "1" AND $m_seek = 0 if $m_p = "1" Then $m_s = "2" TCPSend($m_tcp,$m_playerid & " pause 1 " & @CRLF) Else if $m_f <> $m_fn Then if $m_t = "0" Then if $m_fn <> $m_n Then $m_sq = StringReplace(StringReplace(StringReplace($m_fn, "\", "/"), " ", "%20"), $m_NASPath, "") TCPSend($m_tcp,$m_playerid & " playlist play " & $m_sq & @CRLF) Endif endif $m_t = "" $m_ne = "" $m_f = $m_fn Else if number($m_r) < 12 AND number($m_r) > 1 Then if $m_ne = "" Then $m_amips = FileOpen($m_amip, 0) $m_n = FileReadLine($m_amip) FileClose($m_amip) $m_sq = StringReplace(StringReplace(StringReplace($m_n, "\", "/"), " ", "%20"), $m_NASPath, "") TCPSend($m_tcp,$m_playerid & " playlist insert " & $m_sq & @CRLF) $m_ne = "1" Endif Endif if Number($m_r) < 2 Then $m_t = "0" Endif Endif EndIf Case $m_idle = 0 And $m_s = "2" If $m_p = "?" Then $m_s = "1" TCPSend($m_tcp,$m_playerid & " pause 0 " & @CRLF) EndIf Case $m_idle = 0 AND $m_s = "1" AND $m_seek = 1 $m_seek = 0 $m_ne = "" TCPSend($m_tcp,$m_playerid & " playlist clear" & @CRLF) TCPSend($m_tcp,$m_playerid & " playlist play " & StringReplace(StringReplace(StringReplace($m_fn, "\", "/"), " ", "%20"), $m_naspath, "") & @CRLF) TCPSend($m_tcp,$m_playerid & " pause 1" & @CRLF) sleep(50) TCPSend($m_tcp,$m_playerid & " time " & $m_elt & @CRLF) Sleep(50) TCPSend($m_tcp,$m_playerid & " pause 0" & @CRLF) EndSelect Sleep(50) WEnd TCPSend($m_tcp,$m_playerid & " stop " & @CRLF & " playlist clear " & @CRLF) Sleep(10000) Exit 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