How to generate a random number using the Randomise() function:
This code uses a function in VB to generate a random number. The FOR loop will give a single randomly generated digit between 0 and 9 each time it runs, and will add the new digit onto any digits already created.
For example, the FOR loop currently runs 3 times, which generates a number with 3 digits. You could change this if you wanted a larger or smaller number.
Here are some examples of a number generated by this code:
Again, this uses the RANDOMIZE() function. This code will generate a random number, which will then be used to access a name on a particular line in a file. If the number has already been chosen (and therefore the name displayed), the code deals with not choosing the same number (and therefore name), again.
The array ChosenValue is used to keep track of the numbers already chosen (all numbers are set to "No" to start).
The loop will continue to generate a random number, until the number generated has not been chosen before.
Once the number has been chosen, set the ChosenNumber = "Yes"
Keep repeating for each label you want to populate.
Note: there are 8 names in the textfile and in the example below, there are only 6 labels
Here is what the textfile "names.txt" contains:
Each time the Display button is pressed, the names are populated in a potentially different random order.