Many questions in VB are regarding random numbers. In this tutorial I will try and explain the basic ideas regarding random numbers so it'll be easier for you to create your applications.

Intro - The Rnd Function

The first thing you need to know is the function that generates a random number. The function is called : Rnd. Here is how you use it :

1) Open a new project in VB.
2) In the load event of your form add the following code :

VB Code:
  1. Private Sub Form_Load()
  2.     Dim i As Integer
  3.     For i = 1 To 10
  4.         Debug.Print Rnd
  5.     Next
  6. End Sub

3) Run the project. In the Immediate window you will notice that 10 numbers have been printed.