I have a Form (frmcards) with six Images on it. Each Image has a different picture set into it. I also have a Form (frmMain) with three 'blank' Images, and a Label (Label1) and a Command Button (Command1).
When I click the Command Button, a random number is generated as the Label1.Caption. It does this three times and assigned a picture from frmCards to each of the three 'blank' Images. This works fine, however, it sometimes uses the same picture twice (there are only six to choose from, afterall.) I think I need to use a For/Next Loop to prevent the duplication of the random number, but I really don't know how. Any suggestions?
Thanks!
-I3D
Option Explicit
Private Sub Command1_Click()
Randomize
Label1.Caption = Round((6 - 1 + 1) * Rnd + 1)
Select Case Label1.Caption
Case 1
imgChoice1.Picture = frmCards.imgRedOne.Picture
Case 2
imgChoice1.Picture = frmCards.imgBlueTwo.Picture
Case 3
imgChoice1.Picture = frmCards.imgGreenThree.Picture
Case 4
imgChoice1.Picture = frmCards.imgHeroGold.Picture
Case 5
imgChoice1.Picture = frmCards.imgHeroGray.Picture
Case 6
imgChoice1.Picture = frmCards.imgHeroBlue.Picture
End Select
Randomize
Label1.Caption = Round((6 - 1 + 1) * Rnd + 1)
Select Case Label1.Caption
Case 1
imgChoice2.Picture = frmCards.imgRedOne.Picture
Case 2
imgChoice2.Picture = frmCards.imgBlueTwo.Picture
Case 3
imgChoice2.Picture = frmCards.imgGreenThree.Picture
Case 4
imgChoice2.Picture = frmCards.imgHeroGold.Picture
Case 5
imgChoice2.Picture = frmCards.imgHeroGray.Picture
Case 6
imgChoice2.Picture = frmCards.imgHeroBlue.Picture
End Select
Randomize
Label1.Caption = Round((6 - 1 + 1) * Rnd + 1)
Select Case Label1.Caption
Case 1
imgChoice3.Picture = frmCards.imgRedOne.Picture
Case 2
imgChoice3.Picture = frmCards.imgBlueTwo.Picture
Case 3
imgChoice3.Picture = frmCards.imgGreenThree.Picture
Case 4
imgChoice3.Picture = frmCards.imgHeroGold.Picture
Case 5
imgChoice3.Picture = frmCards.imgHeroGray.Picture
Case 6
imgChoice3.Picture = frmCards.imgHeroBlue.Picture
End Select
End Sub

New Topic/Question
Reply



MultiQuote







|