Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie learning by myself trying to write print statement 1

Status
Not open for further replies.

tjorda23

Technical User
May 25, 2002
2
US
I am working with this book trying to write a single print statement that will print a number at random from a set i.e.

2, 4, 6, 8. I am basically on my own with this book and should have gotten VB6 for Dummies, idiots or something but I am determined to learn this. Can someone help!!
 
Code:
Option Explicit

Private Sub Form_Load()
    Dim HighNum As Long
    Dim LowNum As Long

    Dim RandomNumber As Long

    Randomize

    HighNum = 100
    LowNum = 50

    RandomNumber = Int(((HighNum - LowNum) * Rnd) + LowNum)
    Debug.Print RandomNumber
    
End Sub
 
Your code is fine. However, it is writing the value into the Immediate window, and you can't see the window unless you switch back to the IDE and open the immediate window (from the View menu) while the program is still running.

If you want to see the result from your executable window, either use a MsgBox or put a textbox on the form and set its value to the random number.

Also, this is going to work only once when you open the form. If you want to be able to keep selecting different random numbers, add a button to your form, and move all the code but the Randomize command into the button_click event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top