<html> <body> <input type = "BUTTON" value = "Changement d'images" onclick = "ChangeMap()"><br><br> <Img name="Map_1"/><Img name="Map_2"/><Img name="Map_3"/><Img name="Map_4"/><br> <Img name="Map_5"/><Img name="Map_6"/><Img name="Map_7"/><Img name="Map_8"/><br> <Img name="Map_9"/><Img name="Map_10"/><Img name="Map_11"/><Img name="Map_12"/> </body> <script language = "VBScript"> Dim pathMap : pathMap = CreateObject("Wscript.Shell").CurrentDirectory & "\Images\" Dim ArrayList : Set ArrayList = CreateObject("System.Collections.ArrayList") Sub Window_Onload() ResizeTo 800,600 End Sub Sub ChangeMap() Call LoadMap() Dim icount, i,temp, irnd icount = ArrayList.Count Randomize For i = 1 to icount irnd = ((icount-i) * Rnd) temp = ArrayList(icount-i) Select Case i Case 1 : Map_1.Src = ArrayList(irnd) Case 2 : Map_2.Src = ArrayList(irnd) Case 3 : Map_3.Src = ArrayList(irnd) Case 4 : Map_4.Src = ArrayList(irnd) Case 5 : Map_5.Src = ArrayList(irnd) Case 6 : Map_6.Src = ArrayList(irnd) Case 7 : Map_7.Src = ArrayList(irnd) Case 8 : Map_8.Src = ArrayList(irnd) Case 9 : Map_9.Src = ArrayList(irnd) Case 10 : Map_10.Src = ArrayList(irnd) Case 11 : Map_11.Src = ArrayList(irnd) Case 12 : Map_12.Src = ArrayList(irnd) End Select ArrayList(icount-i) = ArrayList(irnd) ArrayList(iRnd) = temp Next End Sub Sub LoadMap() ArrayList.Clear For Each file in CreateObject("Scripting.FileSystemObject").GetFolder(pathMap).Files ArrayList.Add file.path Next End Sub </script> </html>
Option Explicit Dim aImages, icount, Result, i , iRnd aImages = Array("image1.png","image2.png","image3.png","image4.png","image5.png", _ "image6.png","image7.png","image8.png","image9.png","image10.png") icount = UBound(aImages)+1 ReDim aTabSeries(icount) ReDim aSuites(icount) Randomize For i = 1 To icount aTabSeries(i) = i Next 'on créé le tableau de résultat en "désactivant" ceux trouvés For i = 1 To icount aSuites(i) = 0 While aSuites(i) = 0 iRnd = Int(icount * Rnd) + 1 If aTabSeries(iRnd) <> 0 Then aSuites(i) = aTabSeries(iRnd) aTabSeries(iRnd) = 0 Result = Result & aImages(CStr(aSuites(i))-1) & vbCr End If Wend Next MsgBox Result,,"Images mélangées"
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim aImages, icount, i,temp,irnd
aImages = Array("image1.png","image2.png","image3.png","image4.png","image5.png", _
"image6.png","image7.png","image8.png","image9.png","image10.png")
icount = ubound(aImages)
for i = 0 to icount
iRnd = ((icount-i) * Rnd)
temp = aimages(icount-i)
msgbox "j'ai tiré " & aimages(irnd)
aimages(icount-i) = aimages(irnd)
aimages(iRnd) = temp
next
Randomize for i = 0 to icountj'ai lancé 4 fois le script et à chaque fois l'ordre des images est différent. Donc, la proposition de ucfoutu correspond à la demande de Narfolius.
Dim aImages, icount, i,temp,irnd ReDim arrImages(0) aImages = Array("image1.png","image2.png","image3.png","image4.png","image5.png", _ "image6.png","image7.png","image8.png","image9.png","image10.png") icount = ubound(aImages) Randomize For i = 0 to icount iRnd = ((icount-i) * Rnd) temp = aimages(icount-i) ReDim Preserve arrImages(UBound(arrImages) + 1) arrImages(UBound(arrImages)) = "j'ai tiré " & aimages(irnd) aimages(icount-i) = aimages(irnd) aimages(iRnd) = temp Next MsgBox Join(arrImages,vbCr),,"Le tableau contient " & UBound(arrImages) & " images"
21 oct. 2015 à 00:38
J'étais partie sur ton idée de ce matin et là je vois ton script ...
C'est exactement ce que je recherchais !
Parfait, un grand merci !
21 oct. 2015 à 08:54
21 oct. 2015 à 10:19