VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 300,455 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,594 people online right now. Registration is fast and FREE... Join Now!




RND to generate random numbers.

 

RND to generate random numbers.

Logostomp

28 Jun, 2009 - 02:36 PM
Post #1

New D.I.C Head
*

Joined: 23 Mar, 2009
Posts: 14

Still learning VB on my own. I'm trying to generate a number from 1 to 100. If the person initilizing the script guesses a number. If it's too high or too low, the user then has to input another number. I keep getting a document error when I initilize the script.

CODE
'random.vbs'

'Here is how to produce random integers in a given range:'

dim max,min
max=100
min=1
document.write(Int((max-min+1)*Rnd+min))


This post has been edited by Logostomp: 28 Jun, 2009 - 02:36 PM

User is offlineProfile CardPM
+Quote Post


firebolt

RE: RND To Generate Random Numbers.

28 Jun, 2009 - 10:17 PM
Post #2

D.I.C Lover
Group Icon

Joined: 20 Feb, 2009
Posts: 5,463



Thanked: 75 times
Dream Kudos: 1675
My Contributions
For random numbers, you need to use the random integer code (vb6):
vb

Int(Rnd * 100 + 1)


So are you virtually making a guessing game?
User is offlineProfile CardPM
+Quote Post

Logostomp

RE: RND To Generate Random Numbers.

29 Jun, 2009 - 07:35 AM
Post #3

New D.I.C Head
*

Joined: 23 Mar, 2009
Posts: 14

QUOTE(firebolt @ 28 Jun, 2009 - 10:17 PM) *

For random numbers, you need to use the random integer code (vb6):
vb

Int(Rnd * 100 + 1)


So are you virtually making a guessing game?


Yes. Something that somebody can play. It gives me the number 54.3424 everytime I run the script.

This post has been edited by Logostomp: 29 Jun, 2009 - 10:14 AM
User is offlineProfile CardPM
+Quote Post

Logostomp

RE: RND To Generate Random Numbers.

1 Jul, 2009 - 02:52 PM
Post #4

New D.I.C Head
*

Joined: 23 Mar, 2009
Posts: 14

It keeps showing the number 54.3424. It won't show any other number.

Here's my code.

CODE

'example.vbs'

'Here is how to produce random integers in a given range:'

dim max,min
max=100
min=1
Int(Rnd * 100 + 1)
MsgBox(Rnd * 100 + 1)


If I use this for the last 2 lines, I get 71.

CODE


dp = Int(Rnd * 100 + 1)
MsgBox(dp)


This post has been edited by Logostomp: 1 Jul, 2009 - 02:54 PM
User is offlineProfile CardPM
+Quote Post

firebolt

RE: RND To Generate Random Numbers.

1 Jul, 2009 - 11:36 PM
Post #5

D.I.C Lover
Group Icon

Joined: 20 Feb, 2009
Posts: 5,463



Thanked: 75 times
Dream Kudos: 1675
My Contributions
This is what you need:
CODE

Randomize
x = Int(Rnd * 100)
MsgBox x

User is offlineProfile CardPM
+Quote Post

Logostomp

RE: RND To Generate Random Numbers.

10 Jul, 2009 - 06:22 PM
Post #6

New D.I.C Head
*

Joined: 23 Mar, 2009
Posts: 14

I've gotten closer to solving my problem. Here's the code.
CODE


Dim number, response

Randomize
x = Int(Rnd * 100)


response = inputbox("Please insert a number")

If response2 > number Then
   Msgbox("Please insert a new number")

Else If response2 < number Then
   MsgBox("Please insert a new number")


End If

End If



If the number is equal, I want it to pop up a message. If the number is less than, I want it to pop up a message. If the number is greater than, I want it to pop up a message. It won't pop up anything after inputing the number.
User is offlineProfile CardPM
+Quote Post

firebolt

RE: RND To Generate Random Numbers.

10 Jul, 2009 - 09:45 PM
Post #7

D.I.C Lover
Group Icon

Joined: 20 Feb, 2009
Posts: 5,463



Thanked: 75 times
Dream Kudos: 1675
My Contributions
You need a Do Until - Loop:

This is just an example:
CODE

Dim number, response As String
number = 10
Do Until response = number
response = InputBox("Enter number")
If response <> number Then
MsgBox "Guess Again"
Else
MsgBox "Hooray!!!"
End If
Loop

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:59AM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month