Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to randomize
Message
From
08/11/2001 12:28:16
 
 
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00578749
Message ID:
00579197
Views:
53
>>>hi
>>>my problem is that I want an image to change randomly between 25 picz every time I press a button?
>>>
>>>how du I do?
>>
>>You could store the file names in a string array and use the Rnd function to obtain a random element from it:
>>In Form_Load:
>>
Dim aFiles(1 To 25) As String
>>aFiles(1) = "myfile1.txt"
>>aFiles(2) = "myfile2.txt"
>>aFiles(3) = "myfile3.txt"
>>'.. etc.
>>Randomize
>>In your command button's click:
>>
sNextFile = aFiles(Int(25 * Rnd) + 1)
>>HTH
>
>Don't forget to seed the rand.

Randomize without a seed uses a value based on the system's timer. Is there a pitfall to watch for if you don't specify a seed?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform