Rnd: Random

Add a button, BtnRandom to the form. Make the text say "Random." Double click to open the code view and enter the code as shown below:

Private Sub BtnRandom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
      Handles BtnRandom.Click
   Me.LblMessage.Text = Rnd()
End Sub

After typing "(" the pop-up window displays as shown below:
Rnd

Notice the two small arrows and the words "1 of 2." That means that there are two ways of using this function, or calling it. The first way is to just call it by using the format Rnd( ) with empty parenthesis to indicate that you do not want to pass any arguments to the function. If  you click one of the arrow to look at the second choice it shows Rnd(Number as Single). That indicates that another way to call this function is to use a number inside the parenthesis. We could use a number inside the parenthesis, Rnd(5) , for example.

Run the program and click the random button several times. Each time you click, you get another random number. All of the values are less than 1.

RGB Colors

Add a button, BtnPink to the form. Make the text say "Pink" Double click to open the code view and enter the code as shown below:

Private Sub BtnPink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
      Handles BtnPink.Click
   Me.BackColor = Color.FromArgb(255, 200, 200)
End Sub

When you type the code, instead of selecting one of the colors from the pop-up list, type color "dot" then pick FromArgB from the list. The 4th format for this functions allows you to type in the values for red, green and blue. These values can range from 0 to 255.
INDEX, Built in Functions and Constants, Functions, Random Numbers, How Random Numbers Work, RGB Colors, Random Colors
Next lesson: Visual Basic Calculations

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Functions