Scripts, tutorials, and general Desktop X help
Beginner
Published on February 4, 2007 By sViz In DesktopX Tutorials


UPDATE 11/26/2007: See The WinCustomize Wiki Tutorial for an updated, efficient slideshow tutorial.

Quite some time ago a fellow was looking to learn how to do a picture slide show. Eager to help I jumped right in. I knew how to use On Drop Files to get a picture but with my lack of knowledge I concluded “I'm sure it has something to do with the enumeration of the files dropped and setting a timer” (hehe. Was I a noob….and still am!)

He’s probably figured it out on his own by now but here it is. The simple picture slideshow script that eluded me is now complete! Mwahahahahaha!

Create an object. Go to Properties > Summary and give it a good sized width and height, say 200 by 200. We do this so that when your pictures are applied the object doesn’t take on the size of your pictures (some of them can be huge; wallpaper huge!).
This script I made will start the slideshow as soon as you drop some files onto the object.

Let’s take a look at the script:


Dim files, picscount, grpofpics, numofpics

'Called when the script is executed
Sub Object_OnScriptEnter
picscount = 0
End Sub


Here we have the setup. We have declared all the variables we need to use. ‘Picscount’ is a counter that will count the pictures as they are displayed, ‘grpofpics’ is an array (or a list) of the filenames of all the pictures you select, ‘numofpics’ is the total number of pictures you select. On startup we reset the picscount to 0.


Sub Object_OnDropFiles(files)
grpofpics= Split(files, "|")
'Total number of pics (starting at 0)
numofpics= UBound(grpofpics)
'Set first picture on drop and add to picscount
Object.Picture = grpofpics(0)
picscount = 1
'Start timer on drop
object.SetTimer 1, 2000
End Sub


Here we gather all the information about the pictures when you drop them onto the object. First we get the ‘files’ and split them into an array. Then we check the number of the last file in the array-- Ubound(grpofpics)—which gives us the ‘numofpics’. (An array always starts at zero so if you drop 3 files onto the object it will go 0, 1, 2, making the last file 2.) Next we set the object picture to the first image in the group (that would be zero), and since we’ve just set the picture we now make the picscount = 1. After that we start the 2-second timer.

Sub Object_Ontimer1
'If count is higher than number of pics then reset count
If picscount > numofpics Then picscount = 0
'Set picture
Object.Picture = grpofpics(picscount)
'Add to count
picscount = picscount + 1
End Sub


Now every 2 seconds, on timer, we do three things. First, we check if our count is higher than the number of pictures we have. If so, then we reset the count back to zero. Second, we set the picture by selecting a file from the array ‘grpofpics’. Depending on the ‘picscount’—grpofpics(picscount)—it could be the 1st picture, the 2nd picture, or the 3rd picture.
For instance, if the ‘picscount’ = 0 you’ll get this:

Syntax: Grpofpics(picscount)
Translation: Grpofpics(0)
Plain English: Get me the first picture in the group of files I dropped.

The third and last thing we do after the picture is set is to add 1 to the picscount so that the next time around, 2 seconds later, we can get the next picture in the ‘grpofpics’.


Download the textfile with the script here--Link That’s it! Thanks for reading. Next, Slideshow Part 2: Drag and drop Folders!


Synergy:
DesktopX Wiki- Link
DX Tutorials- Link
My Tutorials- Link
Assorted Tutorials- Link



Comments
on Feb 04, 2007
Great tutorials . . and great links at the end!
on Feb 04, 2007
what happens if I drop a folder on it? *evil grin*
on Feb 04, 2007
what happens if I drop a folder on it? *evil grin*


  DUN DUN DUN!

To be continued.........   

on Aug 29, 2008
Great job:)