Results 1 to 15 of 15

Thread: Random Display Picture (Color & Faded)

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    7

    Random Display Picture (Color & Faded)

    Hi,

    I have 12 color pictures & 12 faded pictures, how to make 11 faded pictures & 1 color picture random display?

  2. #2
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: Random Display Picture (Color & Faded)

    Can you give a bit more detail please?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    7

    Re: Random Display Picture (Color & Faded)

    Thanks for the reply.

    Attached is the screenshot.

    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.
    Attached Images Attached Images  

  4. #4
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: Random Display Picture (Color & Faded)

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    7

    Re: Random Display Picture (Color & Faded)

    How is the logic I should make it?
    Your logic will display the color picture which might be same as one of the faded picture. Anyway to avoid this?

  6. #6
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: Random Display Picture (Color & Faded)

    Are all the pictures already stored? Or are you fading it using VB? If it is the first one how are they stored? As in name formats etc.

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    7

    Re: Random Display Picture (Color & Faded)

    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?

    Thanks a million for your reply.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Random Display Picture (Color & Faded)

    One way would be to start by displaying them all faded, then pick one at random, and display that one as colour.

    If you don't know how to use random numbers in VB, try this tutorial.

  9. #9
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: Random Display Picture (Color & Faded)

    Listen to Si. He has chosen a much better way than me. I think.... Lol.

  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    7

    Talking Re: Random Display Picture (Color & Faded)

    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

    '---------Color pictures

    Randomize (nTemp - 1)
    'Load the Color pictures randomly
    BoxFaded(nTemp - 1).Visible = False
    BoxColor(nTemp - 1).Visible = True
    BoxFaded(nTemp - 1).Picture = LoadPicture(App.Path & "\BoxColor" & nArr(nTemp - 1) & ".jpg")

    End Sub
    --------------------------------------------------------------------------

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Random Display Picture (Color & Faded)

    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.
    Quote 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?

  12. #12

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    7

    Smile Re: Random Display Picture (Color & Faded)

    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):
    Attached Images Attached Images  

  13. #13
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: Random Display Picture (Color & Faded)

    Try something along this lines:

    Code:
    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

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Random Display Picture (Color & Faded)

    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.

  15. #15

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    7

    Re: Random Display Picture (Color & Faded)

    Hi All,

    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
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width