Solved

Random Number

Posted on 1998-08-21
2
194 Views
Last Modified: 2010-04-30
I need to know how to get a random number in Visual Basics.  I know how to write the code in java but as yet haven't found a way to get  V.B jto generate a random number.  Any hints or help is appreciated
0
Comment
Question by:ARROWTHORNE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1430229
First :

Randomize

Rnd(number) => it will return a number between

If number is      Rnd generates
Less than zero      The same number every time, using number as the seed.
Greater than zero      The next random number in the sequence.
Equal to zero      The most recently generated number.
Not supplied      The next random number in the sequence.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1430230
Hi, Here is a code to generate a random integer value from 1 to 6


Option Explicit

Private Sub Command1_Click()
'This example uses the Rnd function to generate a random integer value from 1 to 6.
Dim MyValue
Randomize   ' Initialize random-number generator.

MyValue = Int((6 * Rnd) + 1)    ' Generate random value between 1 and 6.
Label1.Caption = MyValue
End Sub


if you need more help email to: shay@hili.com
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question