-
Oct 12th, 2002, 02:46 AM
#1
Thread Starter
Junior Member
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...?
-
Oct 12th, 2002, 03:16 AM
#2
Hyperactive Member
-
Oct 12th, 2002, 03:20 AM
#3
-= B u g S l a y e r =-
made you a sample Muzamil
VB Code:
Private Sub Form_Load()
Me.AutoRedraw = True
Me.Picture = LoadPicture(GetRndPicFile("D:\data\Graphics\www\backgr"))
End Sub
Private Function GetRndPicFile(sFolder As String) As String
Dim sFile As String
Dim s As String
Dim calle() As String
Dim i As Integer
Dim r As Integer
Randomize
sFile = Dir(sFolder & "\*.jpg")
Do While sFile <> ""
s = s & sFolder & "\" & sFile & vbCrLf
sFile = Dir
Loop
calle = Split(s, vbCrLf)
r = Int(Rnd * (UBound(calle) + 1))
GetRndPicFile = calle(r)
End Function
-
Oct 12th, 2002, 03:23 AM
#4
-= B u g S l a y e r =-
threw in some comments :-)
sorry about the first one, me and commenting ....
VB Code:
Private Sub Form_Load()
'make sure that the picture will be shown
Me.AutoRedraw = True
'set the forms picture to a random picture found in a given folder
Me.Picture = LoadPicture(GetRndPicFile("D:\data\Graphics\www\backgr"))
End Sub
Private Function GetRndPicFile(sFolder As String) As String
Dim sFile As String
Dim s As String
Dim calle() As String
Dim i As Integer
Dim r As Integer
'seed the rnd function for better randomization
Randomize
'get all the jpg files found in the given folder into an array
sFile = Dir(sFolder & "\*.jpg")
Do While sFile <> ""
s = s & sFolder & "\" & sFile & vbCrLf
sFile = Dir
Loop
calle = Split(s, vbCrLf)
'pick one of the files at random
r = Int(Rnd * (UBound(calle) + 1))
GetRndPicFile = calle(r)
End Function
-
Oct 12th, 2002, 03:31 AM
#5
Thread Starter
Junior Member
thx peet
hey peet thx alot for ur great code,, thats wht i wanted, thank u very much.. i really appreciate tht..
-
Oct 12th, 2002, 03:53 AM
#6
-= B u g S l a y e r =-
glad you liked it Muzamil
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|