?
Solved

find a random number in a range ( between 2 numbers)

Posted on 2006-07-17
4
Medium Priority
?
168 Views
Last Modified: 2010-04-30

I need use VB to generate a random number between 2 numbers. for example:

generate a random number between 103 and 205, the program return me 165. something like this.

0
Comment
Question by:rmtogether
[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
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
Harisha M G earned 2000 total points
ID: 17124686
Hi PeterdeB,

LowerNo + Rnd() * (UpperNo - LowerNo)

---
Harish
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 17124697
rmtogether, you might also want to add Int or Round if you want it to be integer..

LowerNo + Int(Rnd() * (UpperNo - LowerNo))
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 17124699
Randomize

Dim iYourNumber As Integer
iYourNumber = CInt((205 - 103) * Rnd) + 103
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 17124704
{too slow...}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

765 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