Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Random Image Generator
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Random Image Generator

 Post Reply Post Reply
Author
skwfalcon16 View Drop Down
Groupie
Groupie


Joined: 07 November 2004
Status: Offline
Points: 41
Post Options Post Options   Thanks (0) Thanks(0)   Quote skwfalcon16 Quote  Post ReplyReply Direct Link To This Post Topic: Random Image Generator
    Posted: 11 January 2005 at 6:29am
Alright, I've run into a problem. I'm setting up an image gallery and want to show a random image from each folder in the gallery on the main page. I can get the picture to show up, but my problem is it's always the same picture. I'm not real sure what I'm missing.
 
Here's the code:
 
Set fso = Server.CreateObjec("Scripting.FileSystemObject")
Set rootFolder = fso.GetFolder(Server.MapPath(strFileUploadPath))
Set subFolder = rootFolder.SubFolders
For each x in subFolder
 num=num+1   
 set fso2=Server.CreateObject("Scripting.FileSystemObject")
 set rootFolder2=fso2.GetFolder(Server.MapPath(strFileUploadPath & "\" & x.name))
 LastMod = rootFolder2.DateLastModified
 Response.Write (vbCrLf & "    <td valign=""top"" align=""center"" bgcolor=""" & strTableColour & """ background=""" & strTableBgImage & """ class=""text"">")
 Response.Write ("<br />")
 Response.Write (vbCrLf & "    <a href=""forum_photos.asp?" & x.name & """ class=""boldLink"">" &  x.Name & "</a><br />")
 
  imgdir = strFileUploadPath & "\" & x.name
  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  Set objFolderObject = objFSO.GetFolder(Server.MapPath(imgdir))
  Set objFSO = Nothing
  Set objFileCollection = objFolderObject.Files
  Set objFolderObject = Nothing
  intFileNumberToUse = Int(rnd * objFileCollection.Count) + 1
  If objFileCollection.Count = 0 Then
   Response.Write ("<br />No Pictures In Gallery<br /><br />")
  Else  
  
  intFileLooper = 1
  For Each objFile in objFileCollection
   If intFileLooper = intFileNumberToUse Then
    Set objImageFileToUse = objFile
    Exit For
   End If
   intFileLooper = intFileLooper + 1
  Next
  Set objFileCollection = Nothing
  strImageSrcText = imgdir & "\" & objImageFileToUse.Name
  Set objImageFileToUse = Nothing
  Response.Write ("<br />")
 Response.Write (vbCrLf & "    <a href=""forum_photos.asp?" & x.name & """><img src=""/thumbnailimage.aspx?filename=" & strImageSrcText & "&width=" & ImgWidth &"&height=" & ImgHeight & """ border=""0"" align=""middle""></a><br / >")
 Response.Write ("<br />")
 
 End If
 
 Response.Write LastMod 
 Response.Write (vbCrLf & "    </td>")
  
 numGallery = numGallery + 1
    
 If numGallery = 3 Then
  Response.Write (vbCrLf & "  </tr>")
  Response.Write (vbCrLf & "  <tr>")
  numGallery = 0
 End if
Next    
 If numGallery <> 0 Then
  Do While numGallery <= 2
   Response.Write (vbCrLf & "    <td valign=""top"" bgcolor=""" & strTableColour & """ background=""" & strTableBgImage & """ class=""text"">&nbsp;</td>")
   numGallery = numGallery + 1
  Loop
  Response.Write (vbCrLf & "  </tr>")
 End If
 
Any help would be greatly appreciated!
Back to Top
Phat View Drop Down
Senior Member
Senior Member


Joined: 23 February 2003
Status: Offline
Points: 386
Post Options Post Options   Thanks (0) Thanks(0)   Quote Phat Quote  Post ReplyReply Direct Link To This Post Posted: 12 January 2005 at 6:25am
Try putting Randomize before
 intFileNumberToUse = Int(rnd * objFileCollection.Count) + 1
Back to Top
skwfalcon16 View Drop Down
Groupie
Groupie


Joined: 07 November 2004
Status: Offline
Points: 41
Post Options Post Options   Thanks (0) Thanks(0)   Quote skwfalcon16 Quote  Post ReplyReply Direct Link To This Post Posted: 12 January 2005 at 3:12pm
Awesome!
 
That worked...thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.