When click the start button, expecting 11 random faded pictures display, and only one color picture display. And the color picture can click for a question.
Currently I only manage to random display the color pictures on the 12 boxes there, which not fit my beginning idea at all.
Well all you would do is get your 11 random b&w pictures as you already do and then have a seperate sub procedure where you would choose your random colour picture.
Sorry I did not make everything clear enough here.
I wish to use VB to faded the picture but I failed to do so,
so I stored the color pictures as picColor1.jpg - picColor12.jpg,
and faded picture as picFaded1.jpg - picFaded12.jpg
And now using array to display the color / faded pictures randomly. But how to make only display one color pic & 11 faded picture after I clicked Start?
Hi, the coding at below is able to do it. But how to make it won't repeat display the same picture for Color Picture while the Faded Picture is displayed?
------------------------------------------------------------------------
Private Sub start_Click()
'----------Faded Pictures
Dim nArr(12) As Long
Dim n As Long
Dim nTemp As Long, nRand As Long
For n = 0 To 11
nArr(n) = n + 1
Next
Randomize
For n = 12 To 1 Step -1
nRand = Int(Rnd * n)
nTemp = nArr(nRand)
nArr(nRand) = nArr(n - 1)
nArr(n - 1) = nTemp
Next
'Load the Faded pictures randomly
For n = 0 To 11
BoxFaded(n).Visible = True
BoxFaded(n).Picture = LoadPicture(App.Path & "\BoxFaded" & nArr(n) & ".jpg")
Next
When you post code, please use Code (or VBCode) tags, which can be done with the buttons just above the area you type into - it makes your post much easier to read.
Originally Posted by earthy
But how to make it won't repeat display the same picture for Color Picture while the Faded Picture is displayed?
I'm not sure what you mean by this, could you clarify?
Ooops, sorry about that, just aware there's a button for "Code" & "VBCode".
Below is the wrong display, which show duplicate picture (one in grey, one in color):
dim faded as integer
dim coloured as integer
Do
faded = Mid(name_of_faded_file,(Len(name_of_faded_file)-4),1)
coloured = Mid(name_of_coloured_file,(Len(name_of_coloured_file)-4),1)
Loop Until faded <> coloured
I see... well your code for the color picture is not quite right at the moment - for a start you aren't actually picking a random number!
Your use of the nArr array to stop duplication for the Faded pictures is good, and you should simply be able to re-use that.
Unless you particularly want to have two sets of pictureboxes (perhaps your other code needs them), you would be better off using just one set instead (ie: just BoxFaded, perhaps renamed to something else).
Your code for the color boxes should do the following:
pick a random number (between 0 and 11);
if using two sets of pictureboxes, hide the relevant BoxFaded (of the random number you picked) and show the relevant BoxColor
load the picture (again, using the random number you picked)
..have a go at doing that, and if you have problems show us that code.
Tq very much for d advice. Below is my full random VB coding & screenshot:
Code:
Private Sub start_Click()
'----------Display 12 Faded Pictures Randomly
Dim nArr(12) As Long
Dim n As Long
Dim nTemp As Long, nRand As Long
For n = 0 To 11
nArr(n) = n + 1
Next
Randomize
For n = 12 To 1 Step -1
nRand = Int(Rnd * n)
nTemp = nArr(nRand)
nArr(nRand) = nArr(n - 1)
nArr(n - 1) = nTemp
Next
For n = 0 To 11
BoxFaded(n).Visible = True
BoxFaded(n).Picture = LoadPicture(App.Path & "\BoxFaded" & nArr(n) & ".jpg")
Next
'---------Random Display One Color picture
n = 5
BoxFaded(n).Visible = False
BoxColor(n).Visible = True
BoxColor(n).Picture = LoadPicture(App.Path & "\BoxColor" & nArr(n) & ".jpg")
BoxColor(n).Enabled = True
End Sub