Page 1 of 1 1
Topic Options
#134421 - 2005-02-24 12:34 AM A script has stopped working
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
The funny thing is, it's a script that has been working ever since I wrote it...

I get the following error:

Quote:

ERROR : undefined variable [$count]!
Script: J:\playlist.kix
Line : 30




Here's the script (with the external UDFs trimmed off):

Code:
Break on


Global $starttime

$rc = runningtime()

If Exist(@SCRIPTDIR + "\rock.m3u") = 1
DEL @SCRIPTDIR + "\rock.m3u"
EndIf

If Exist(@SCRIPTDIR + "\pop.m3u") = 1
DEL @SCRIPTDIR + "\pop.m3u"
EndIf

If Exist (@SCRIPTDIR + "\all music.m3u") = 1
DEL @SCRIPTDIR + "\all music.m3u"
EndIf

? "Generating base playlists..."
$rockarray = Dirlist(@SCRIPTDIR + "\rock\*.mp3",2+4)
$poparray = Dirlist(@SCRIPTDIR + "\pop\*.mp3",2+4)
$allmusic = JoinArray($rockarray,$poparray)

$ = WriteFile(@SCRIPTDIR + '\Rock.m3u',$rockarray)
$ = WriteFile(@SCRIPTDIR + '\Pop.m3u',$poparray)
$ = WriteFile(@SCRIPTDIR + '\All Music.m3u',$allmusic)

$rockartists = DirPlus(@SCRIPTDIR + "\rock\","/ad")

$count = 3

For Each $artist In $rockartists
$artistiso = Split($artist,"\")
$x = UBound($artistiso)
If Exist (@SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u") = 1
DEL @SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u"
EndIf
Select
Case $artistiso[$x] = "Various Artists"
$VARock = Dirlist($artist + "\*.mp3",2+4)
Case $artistiso[$x] = "Miscellaneous"
$MSRock = Dirlist($artist + "\*.mp3",2+4)
Case 1
$artistm3u = Dirlist($artist + "\*.mp3",2+4)
? "Generating Playlist for " + $artistiso[$x]
$ = WriteFile(@SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u",$artistm3u)
$count = $count + 1
EndSelect
Next

$popartists = DirPlus(@SCRIPTDIR + "\pop\","/ad")

For Each $artist In $popartists
$artistiso = Split($artist,"\")
$x = UBound($artistiso)
If Exist (@SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u") = 1
DEL @SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u"
EndIf
Select
Case $artistiso[$x] = "Various Artists"
$VApop = Dirlist($artist + "\*.mp3",2+4)
Case $artistiso[$x] = "Miscellaneous"
$MSpop = Dirlist($artist + "\*.mp3",2+4)
Case 1
$artistm3u = Dirlist($artist + "\*.mp3",2+4)
? "Generating Playlist for " + $artistiso[$x]
$ = WriteFile(@SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u",$artistm3u)
$count = $count + 1
EndSelect
Next

? "Generating miscellaneous playlists..."
If Exist(@SCRIPTDIR + "\playlists\Miscellaneous Rock.m3u") = 1
DEL @SCRIPTDIR + "\playlists\Miscellaneous Rock.m3u"
EndIf

If Exist(@SCRIPTDIR + "\playlists\Miscellaneous Pop.m3u") = 1
DEL @SCRIPTDIR + "\playlists\Miscellaneous Pop.m3u"
EndIf

$MiscRock = JoinArray($MSRock,$VARock)
$ = WriteFile(@SCRIPTDIR + "\playlists\Miscellaneous Rock.m3u",$MiscRock)
$Miscpop = JoinArray($MSpop,$VApop)
$ = WriteFile(@SCRIPTDIR + "\playlists\Miscellaneous Pop.m3u",$Miscpop)

$count = $count + 2

$rc = runningtime()

MessageBox("Processed " + $count + " playlists in " + $rc + " seconds.","Finished!",64,0)
Quit



I'm a little confused as to why it's telling me that the variable is undefined, as I explicitly define $count. If I move that line up to the top of the script, it then bugs me that $artist in line 32 is undefined...

I don't think I've made any changes to my system since the last time I successfully ran the script...any tips as to the nature of the problem would be appreciated.

FWIW, I'm using KiX 4.22


Edited by eriqjaffe (2005-02-24 12:34 AM)

Top
#134422 - 2005-02-24 12:38 AM Re: A script has stopped working
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Take these lines out of DirPlus ...

$ex1 = SetOption(Explicit,on)

$ex2 = SetOption(NoVarsInStrings,on)

Top
#134423 - 2005-02-24 12:39 AM Re: A script has stopped working
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Properly code your script by explicitly using
Code:

$ex1 = SetOption('Explicit','o'n)
$ex2 = SetOption('NoVarsInStrings','on')


DIMming all variables and not using variables inside strings.
_________________________
There are two types of vessels, submarines and targets.

Top
#134424 - 2005-02-24 12:40 AM Re: A script has stopped working
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
They shouldn't be in the UDF at all.
Top
#134425 - 2005-02-24 12:47 AM Re: A script has stopped working
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Agreed.
_________________________
There are two types of vessels, submarines and targets.

Top
#134426 - 2005-02-24 10:00 AM Re: A script has stopped working
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

I'm a little confused as to why it's telling me that the variable is undefined, as I explicitly define $count. If I move that line up to the top of the script, it then bugs me that $artist in line 32 is undefined...




Kind of.

You explicitly assign a value to the variable which implicitly declares it.

Explicitly declaring a variable can only be done with the DIM or GLOBAL statements (don't use GLOBAL).

The option SetOption("Explicit","ON") which is in one of your UDFs instructs KiXtart to handle undeclared variables as an error.

The "Explicit" option is global in scope and should never be set in a UDF unless the UDF also resets it to it's original value.

Having said that, *you* should set it at the top of your script and then declare all your variables. It's good coding practice, will enable you to track typos and bugs much more quickly and if you ever post to the UDF forum you will be required to explicitly declare all variables.

Top
#134427 - 2005-02-24 03:50 PM Re: A script has stopped working
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
Thanks, everybody...this morning, a couple other scripts I run routinely also begain failing mysteriously. After re-installing WSH, the problems have cleared up...I'm not sure what happened to WSH, but that appears to have been the issue.

Ah, well. At least I picked up some Best Practice tips.

Thanks again.

Top
#134428 - 2005-02-25 04:09 AM Re: A script has stopped working
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
WSH has nothing to do and is independent of KiXtart. Your specific problem wwas related to not declaring variables inside KiXtart.
_________________________
There are two types of vessels, submarines and targets.

Top
#134429 - 2005-02-25 04:16 PM Re: A script has stopped working
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
But...the script as posted worked fine once I re-installed WSH. And, as I mentioned, it had worked fine for months up until the other day, even without declaring the variables...

Before reinstalling WSH, I went through the script, declaring all the variables, and was still getting odd behavior. In particular, the DirPlus calls were not generating arrays, as they prevoiusly had..unless I was declaring the variables incorrectly, which is possible. Is this the correct method:

Code:
DIM $artist,$artistiso,$x

...etc?

I would think that it could have been a UDF which requires WSH causing the problem, but none of the UDFs in the script list WSH as a prerequisite.

Top
#134430 - 2005-02-25 04:29 PM Re: A script has stopped working
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Without being able to see all the code, my guess is that one of the UDFs sets the "Explicit" flag, then resets it when it exits.

When there is an unexpected error condition the UDF exits early so never sets "Explicit" back to it's correct value.

When you fixed the error condition by reinstalling WSH the UDF worked correctly, setting "Explicit" on and off so that the rest of your script works again.

This is why I said that any SetOption() changes made in a UDF must be reset in all circumstances, including abnormal exits.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.056 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org