Results 1 to 6 of 6

Thread: random pictures

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Location
    Tanzania (Arusha)
    Posts
    17

    Question random pictures

    hello t here!!!
    Can anyone please give me the code on how to put a random picture whenever i load a form?

    I mean for eg.. i have a picturebox named picture1.. what if i want to put different pictures at form load...?
    Muz

  2. #2
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Question More Specific

    where are the pictures to use? I mean do u want to use random pictures found on any PC, or a set of pictures to be ditributed with your application???
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    made you a sample Muzamil

    VB Code:
    1. Private Sub Form_Load()
    2.     Me.AutoRedraw = True
    3.     Me.Picture = LoadPicture(GetRndPicFile("D:\data\Graphics\www\backgr"))
    4. End Sub
    5.  
    6. Private Function GetRndPicFile(sFolder As String) As String
    7.     Dim sFile As String
    8.     Dim s As String
    9.    
    10.     Dim calle() As String
    11.     Dim i As Integer
    12.     Dim r As Integer
    13.     Randomize
    14.     sFile = Dir(sFolder & "\*.jpg")
    15.     Do While sFile <> ""
    16.         s = s & sFolder & "\" & sFile & vbCrLf
    17.         sFile = Dir
    18.     Loop
    19.     calle = Split(s, vbCrLf)
    20.     r = Int(Rnd * (UBound(calle) + 1))
    21.    
    22.     GetRndPicFile = calle(r)
    23. End Function
    -= a peet post =-

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629

    threw in some comments :-)

    sorry about the first one, me and commenting ....

    VB Code:
    1. Private Sub Form_Load()
    2.     'make sure that the picture will be shown
    3.     Me.AutoRedraw = True
    4.     'set the forms picture to a random picture found in a given folder
    5.     Me.Picture = LoadPicture(GetRndPicFile("D:\data\Graphics\www\backgr"))
    6. End Sub
    7.  
    8. Private Function GetRndPicFile(sFolder As String) As String
    9.     Dim sFile As String
    10.     Dim s As String
    11.    
    12.     Dim calle() As String
    13.     Dim i As Integer
    14.     Dim r As Integer
    15.    
    16.     'seed the rnd function for better randomization
    17.     Randomize
    18.    
    19.     'get all the jpg files found in the given folder into an array
    20.     sFile = Dir(sFolder & "\*.jpg")
    21.     Do While sFile <> ""
    22.         s = s & sFolder & "\" & sFile & vbCrLf
    23.         sFile = Dir
    24.     Loop
    25.     calle = Split(s, vbCrLf)
    26.    
    27.     'pick one of the files at random
    28.     r = Int(Rnd * (UBound(calle) + 1))
    29.     GetRndPicFile = calle(r)
    30. End Function
    -= a peet post =-

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Location
    Tanzania (Arusha)
    Posts
    17

    Talking thx peet

    hey peet thx alot for ur great code,, thats wht i wanted, thank u very much.. i really appreciate tht..
    Muz

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    glad you liked it Muzamil
    -= a peet post =-

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