Microsoft KB Archive/314811

From BetaArchive Wiki

Article ID: 314811

Article Last Modified on 3/20/2004



APPLIES TO

  • Microsoft Internet Explorer 5.0
  • Microsoft Internet Explorer 5.5



This article was previously published under Q314811

SUMMARY

This article describes how to use sample Windows Script Host (WSH) code to programmatically create a DHTML slide show in a folder that contains images.

NOTE: This article uses custom DHTML that may not be available in all browsers.

back to top

Step 1: Create the WSH Sample

NOTE: Because there are several versions of Microsoft Windows, the following steps may be different on your computer. If they are, see your product documentation to complete these steps.

  1. Click Start, point to Programs, point to Accessories, and then click Notepad.
  2. Type or paste the following WSH code into Notepad:

    Option Explicit
    
    ' slideshow delay in milliseconds
    Const lngDelay = 2000
    
    ' valid file extensions for slides
    Const strValid = ".jpg.jpeg.gif.png"
    
    ' output file name
    Const strFileName = "slideshow.htm"
    
    ' ******************** DO NOT MODIFY BELOW THIS LINE ********************
    
    ' Define variables.
    Dim objFSO
    Dim objOutput
    Dim strImage
    Dim strExt
    Dim strFirst
    Dim lngCount
    Dim objFolder
    Dim objFile
    
    ' Create the output file.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objOutput = objFSO.CreateTextFile(strFileName)
    
    ' Output the page header and beginning of slideshow script.
    objOutput.WriteLine "<html>" & vbCrLf & "<head>"
    objOutput.WriteLine "<script language=""javascript"">" & vbCrLf & "<!--"
    objOutput.WriteLine "function PreloadImage(tmpSImage)"
    objOutput.WriteLine "{"
    objOutput.WriteLine vbTab & "var tmpOImage=new Image();"
    objOutput.WriteLine vbTab & "tmpOImage.src=tmpSImage;"
    objOutput.WriteLine vbTab & "return tmpOImage;"
    objOutput.WriteLine "}"
    objOutput.WriteLine "var strImage = new Array("
    
    ' Get a folder object from the current to parse for files.
    Set objFolder = objFSO.GetFolder(".")
    
    ' Loop through the files in the folder.
    For Each objFile In objFolder.Files
      ' Does the file have an extension?
      If InStr(objFile.Name,".") Then
        strImage = objFile.Name
        ' Get the file name extension.
        strExt = LCase(Mid(strImage,InStrRev(strImage,".")))
        ' Is the extension a valid extension?
        If InStr(strValid,strExt) Then
          ' Output the code to load the image.
          objOutput.Write "'" & strImage & "',"
          If Len(strFirst) = 0 Then strFirst = strImage
          lngCount = lngCount + 1
        End If
      End If
    Next
    objOutput.WriteLine "''" & vbCrLf & ");"
    
    ' Output the rest of the slideshow script.
    With objOutput
      .WriteLine "var objImage = new Array(strImage.length-2);"
      .WriteLine "var lngCount = strImage.length - 1;"
      .WriteLine "function LoadImages()"
      .WriteLine "{"
      .WriteLine vbTab & "if (lngCount >= 0)"
      .WriteLine vbTab & "{"
      .WriteLine vbTab & vbTab & "document.all['theSPN'].innerHTML=lngCount;"
      .WriteLine vbTab & vbTab & "objImage[lngCount] = PreloadImage(strImage[lngCount]);"
      .WriteLine vbTab & vbTab & "lngCount--;"
      .WriteLine vbTab & vbTab & "setTimeout('LoadImages()', 50);"
      .WriteLine vbTab & "}"
      .WriteLine vbTab & "else"
      .WriteLine vbTab & "{"
      .WriteLine vbTab & vbTab & "lngCount = 0;"
      .WriteLine vbTab & vbTab & "document.all['theDIV'].innerHTML='<img src=""" & strFirst  & """ id=""theIMG"">';"
      .WriteLine vbTab & vbTab & "setTimeout('SwapImage()'," & lngDelay & ");"
      .WriteLine vbTab & "}"
      .WriteLine "}"
      .WriteLine "function SwapImage()"
      .WriteLine "{"
      .WriteLine vbTab & "++lngCount;"
      .WriteLine vbTab & "if (lngCount<strImage.length-1)"
      .WriteLine vbTab & "{"
      .WriteLine vbTab & vbTab & "document.all['theIMG'].src=objImage[lngCount].src;"
      .WriteLine vbTab & vbTab & "setTimeout('SwapImage()'," & lngDelay & ");"
      .WriteLine vbTab & "}"
      .WriteLine "}"
      .WriteLine "//-->" & vbCrLf & "</script>"
      .WriteLine "</head>" & vbCrLf & "<body onLoad=""setTimeout('LoadImages()'," & lngDelay * 2 & ");"">"
      .WriteLine "<div align=""center"" id=""theDIV""><h2>Please wait...<br>"
      .WriteLine "Loading " & lngCount & " images... (<span id=""theSPN"">0</span>)</h2></div>"
      .WriteLine "</body>" & vbCrLf & "</html>"
    End With
    
    ' Close the output file.
    objOutput.Close
                        
  3. Save the file to your desktop as Slideshow.vbs.

back to top

Step 2: Create the Slide Show

  1. Copy the Slideshow.vbs script to a folder that contains images (for example, to your My Documents\My Pictures folder).
  2. Double-click the script to run it.


When the script is finished running, you will have a file named Slideshow.htm, which contains the DHTML script for the slide show.

back to top

REFERENCES

For additional information about how to use DHTML in Internet Explorer and how to troubleshoot possible errors with DHTML, click the article numbers below to view the articles in the Microsoft Knowledge Base:

213872 How to Create a Scrolling Message in Browser's Status Bar


248630 Complex DHTML Pages Cause Memory Usage to Increase Beyond Bounds


back to top

Keywords: kbhowtomaster kbinfo kbdswmanage2003swept KB314811