RandomImage

Gets a random image from a folder of files, passed as an unMapPathed (HTML) folder.
Tries 10 times to read an image (gif, jpg and png only), returns blank if not

Function RandomImage(Path_UnMapPathed)
 ' Gets a random image from a folder passed through HTML folder
 ' Needs FilesIn, CutString3
 RandomImage    = ""
 ServerFolder   = Server.MapPath(Path_UnMapPathed)
 AllFees     = FilesIn(Path_UnMapPathed, "|")
 Cou      = Len(AllFees) - Len(Replace(AllFees, "|" ,""))
 If Cou = 0 Then Exit Function
 DoCo      = 0
 Do
  DoCo     = DoCo + 1
  If DoCo > 10 Then Exit do ' Try to find random image 10 times only
  Randomize
  GetRnd    = Int((Cou * Rnd) + 1)
  F1      = CutString3(AllFees, GetRnd , "|")
  F2      = UCase(Right(F1,4))
  If F2 = ".JPG" Or F2 = ".GIF" Or F2 = ".PNG" Then Exit Do
 Loop
 RandomImage    = F1
End Function

Parameters

Path_UnMapPathed

Views 53 Downloads 18

Perm link