venerdì 7 novembre 2008

[ASP] - Visualizzare Immagini Casuali ad ogni Refresh

'-------------------VISUALIZZAZIONE IMMAGINI CASUALI----------------------------------'
'===============================================================================
'Prende automaticamente i file dalla cartella specificata in IMGS_DIR

IMGS_DIR = "./percorso_cartella/"

Randomize



' Variables for our FileSystemObject objects
Dim objFSO, objFolderObject, objFileCollection, objFile

' A pair of integers for our random image selection
Dim intFileNumberToUse, intFileLooper

' A "handle" to the file we choose to use
Dim objImageFileToUse

' A variable to build our image tag
Dim strImageSrcText

' Lets see what's in the directory:
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolderObject = objFSO.GetFolder(Server.MapPath(IMGS_DIR))
Set objFSO = Nothing

Set objFileCollection = objFolderObject.Files
Set objFolderObject = Nothing

' Get a count of files and use it to generate a random
' number from 1 to the count.
intFileNumberToUse = Int(objFileCollection.Count * Rnd) + 1

' Set up loop control so we exit when we get to the random
' file number we just picked.
intFileLooper = 1
For Each objFile in objFileCollection
If intFileLooper = intFileNumberToUse Then
' Get a "handle" on the appropriate file
Set objImageFileToUse = objFile
Exit For
End If
intFileLooper = intFileLooper + 1
Next

Set objFileCollection = Nothing

' Build our img src tag text
strImageSrcText = IMGS_DIR & objImageFileToUse.Name

Set objImageFileToUse = Nothing

' Show the image:
%>
<img
src = "<%= strImageSrcText %>"
width = "614"
height = "70"
alt = "nome_img"
border = "0"
/>

Nessun commento: