Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Quick Question - How To Msgbox A Random Integer Between 0 And X?


where x is a number (less than 10)?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Display An Integer In MsgBox
Dim result As Integer
result = theModel.FindLogicalPackages("TempPackage").Count


If (result = 0) Then
theModel.RootLogicalPackage.AddLogicalPackage ("TempPackage")
End If

result = theModel.FindLogicalPackages("TempPackage").Count

MsgBox (result + "The Capsule was duplicated in Temp Package")

Is the test (if (result=0)) is fine or not,
should I use if (result Is 0) ?????

Why do I have a type mismatch error when I try to display the value of result?

thanks

How Do You Display A Variable (An Integer) In A MsgBox
Just letting you all know... Me = Good At TURING ONLY, me not = good at VB.
yeah...
so i need to display a variable which has kept count for the user, and i need to display tha variable number, which i or the user don't know, in the message box.

In turing it would be something like this:
put "It Took You ", guesses, " Guesses!"

Hope that helped, it sort of didn't help me...

Returning A Random Integer
Hello, I was wondering how would I return a random integer between 1 and 4 (including 1 and 4) to a variable?

Thanks.

Generate A Random Integer
Hello I am trying to remember how to set it to generate a random integer in a variable. the best way to explain what I am trying to learn is Say you want to when you click on a command button you want it to set strVal to a number between 1 and 6 (sorta like rollin a dice) for a game a chance type thing.

I thought it would be


VB Code:
strVal =Rnd(1 - 6)


but could not get it to work.

Breaking An Integer To 3 Random Pieces
how can i break an integer to three random pieces(e.g. for 800; 300,225,275).

How Do I Make A Random Integer Between 100 And 1000?
I am new at VB. I'm working off VB 5. For school i need some help on a program. Would someone be willing to help?For a program i am creating in vb 5 i need to have a listbox compiled with random integers between 100 and 1000. Any ideas? I have to create 100 integers random integers between 100 and 1000. This is what i have so far:

General:



VB Code:
Const MAXITEM=100Dim A(MAXITEM) As Integer cmdGenerate_ClickFor x=1 to MAXITEM    'Generate Random Int between 100 and 1000    A(x)=Rnd    lstRandomInt.AddItem Str$(A(X))Next x 'now this is what i thought would work    Do         If A(x) < 100 then                  A(X)=A(X)*Rnd         End if    Loop until A(x) > 100     Do            If A(x)>1000 then                  A(X)=A(X)/Rnd            End If     Loop until A(x)  < 1000


Now i know there is a loop hole, the number could become lower than 100 again but i dont know how to fix that. If anyone knows how i can create 100 random integers between 100 and 1000 and add them each into a listbox please let me know.

Generate Unique Random Integer In Given Range
I am sure there must be a function available that can generate a unique random integer in a given range.

Inputs:

Upper limit
Lower Limit
Array of integers between upper and lower limit.

Output:

A random integer that does not exist in the [array of integers between upper and lower limit], but is not greater than the upper limit or not less than the lower limit.

Example:

Upper limit = 10
Lower limit = 1
Input Array = {1,6,2,9,4,3}

An allowed output is an element of the set {5,7,8,10)

If you have the solution I would be most grateful.

I received an email that shows that it does not matter in what sequence letters occur in a word, but providing the first and last letters of the word are the same, then you will be able to read the word correctly without even having to think about the order of the letters. So I am going to use this principle as part of a password generator to generate passwords that are easy for users to remember. An example:

My nmae is Mike and I am a cmptuoer pmeoramrgr.

How Do You Assign A Random Number To A An Integer Variable
Code:
Randomize
A = Rnd(9)
B = Rnd(9)
C = Rnd(9)
D = Rnd(9)
E = Rnd(9)
F = Rnd(9)
G = Rnd(9)
H = Rnd(9)
DoEvents

That's what I have and all it gives me is 0 and 1

Simple Random File Integer Saves/read
I want to save a (single diamension) array of type INTEGER to a random
(ie binary) file, and read it again into the array.
I am having trouble reading the data & the lenght of data
Is this correct?
Or is there a quicker/simplier way?
write:
open "blaa" for random as #1 len =2
for x= 0 to y
put #1,x+1,array(x)
next x
close 1
Read:
x=0
open "blaa" for random as #1 len =2
do while lof(1)
get #1,x+1,array(x)
x=x+1
loop
close 1

2 Quick Msgbox Questions.
Hey there ,

I have two quick message box questions.

1) Is it possible to have a YES & NO option with a question mark icon.
2) How do i say, if the user presses yes, do this..?

Quick Question MsgBox
I have a message box as follows.

MsgBox("Flipped" & Heads + InputValue & "times.")

When I get to the point where I see the box there is no space between Flipped the data output and then times so it looks like Flipped5times. I can't remember how to get that space in there.

Quick Msgbox Question
Hey, I am wondering how to get a msgbox to pop up in front of all other apps. Thanx everyone for the help!! =)

MsgBox Limitations, Please Quick Help Required, If Possible...
Hi everybody,

I have a simple word user form, I added a vba command button on the form which when pressed brings up a MsgBox:

Code:Private Sub CommandButton1_Click()
    MsgBox ("Article 3" _
    & vbCr & vbCr & "1. In assuming their responsibilities and obligations" _
    & " under the international conventions, Member States shall ensure that" _
    & " their competent administrations can assure an appropriate enforcement" _
    & " of the provisions of the international conventions, in particular with" _
    & " regard to the inspection and survey of ships and the issue of certificates" _
    & " and exemption certificates. Member States shall act in accordance with" _
    & " the relevant provisions of the Annex and the Appendix to IMO Resolution" _
    & " A.847(20) on guidelines to assist flag States in the implementation of" _
    & " IMO instruments." _
    & vbCr & vbCr & "2. Where for the purpose of paragraph 1 a Member State decides" _
    & " with respect to ships flying its flag:" _
    & vbCr & vbCr & "(i) to authorize organizations to undertake fully or in part" _
    & " inspections and surveys related to certificates including those for the" _
    & " assessment of compliance with Article 14 and, where appropriate, to issue2" _
    & " or renew the related certificates; or" _
    & vbCr & vbCr & "(ii) to rely upon organizations to undertake fully or in part the" _
    & " inspections and surveys referred to in subparagraph(i);"), , "COUNCIL DIRECTIVE 94/57/EC"
End Sub

Unfortunately, it seems to have a limit on characters, I need to add more text. Please any alternative suggestions would be very much appreciated.

Kind regards,


Arabella





Edited by - AbbydonKrafts on 11/3/2006 10:28:41 AM

Quick Question - How Would You Msgbox All Contents Of A Listbox...
How would you msgbox all contents of a listbox one at a time? Anyone know?

2 Quick Questions - Msgbox And Form Z-order
that I can't seem to find answers to..

1. Is it possible to make the standard MsgBox appear in a position centered in another form? Similar to the way "startUpPosition-CenterOwner" usually works for normal forms.

2. I have a form that is supposed to represent the "Desktop" of an application. I want it to stay behind all the the forms, but it also has controls on it that need to be used (icons, etc). If I use Z-order to keep it always in the background, it won't allow you to click on the form and use the controls.. is there any way around this?

Sorry for putting two questions in one post!



Edited by - Shay23 on 11/11/2003 1:03:26 PM

How Can You Msgbox A Random Entry In A Listbox?
and add a 4 digit random number to it?

Quick Easy Random
how do i randomly generate a number between

5 and 15

?

How Can You Msgbox A Random 6 Character String Of Letters?
followed by a 2digit number?

anyone know?

Quick Random Access File Help?
Okay, I have spent about 4 hours trying to figure this out (yes, that is how stupid i am).

what I need to be able to do is enter in an Artist, album, the year it was made (an integer), and the genre of music it is (this is all done in a textbox). I was able to do that no problem, but I didn't know I had to use the random access file function... So you put stuff into the textboxes, hit add, and it's supposed to add the record into a RAF.

Here's what I have so far...

Code:
Option Explicit
Dim intCount As Integer
Dim udtFoo(50) As CDcount

Private Type CDcount
Artist As String * 30
Album As String * 30
Genre As String * 30
Year As Integer
End Type

Private Sub cmdDone_Click()
Unload frmCD
End Sub

Private Sub cmdSave_Click()
Dim intFile As Integer
Dim intDATA As Integer

intFile = FreeFile

udtFoo(intCount).Artist = txtArtist.Text
RTrim (udtFoo(intCount).Artist)
udtFoo(intCount).Album = txtAlbum.Text
RTrim (udtFoo(intCount).Album)
udtFoo(intCount).Genre = txtGenre.Text
RTrim (udtFoo(intCount).Genre)
udtFoo(intCount).Year = txtYear.Text
RTrim (udtFoo(intCount).Year)

intDATA = LenB(udtFoo(intCount))

Open txtPath.Text For Random As #intFile Len = intDATA
Put #intFile, , udtFoo(intCount)
Close #intFile

intCount = intCount + 1
End Sub

The thing is, when I try to add stuff to the file, not only is that Rtrim thing not working right, my number isn't displaying (in the text file). Along with that, it'll only add 1 entry and won't keep adding onto the text file...

Any help would be greatly appreciated (shouldn't be much trouble for you programming gods )

Hi Quick Thing, Cant Remember How To Generate A Random Number :S :P
Hi, can someone quickly tell me how to generate a random number, my mind has gone blank...

Thanks, Lana

Retrieving Data From Random Files Created Using Quick Basic
I am trying to write a VB routine to retrieve data from Random access files created using QB 4.5. The data was put using "Left D$ = MKI$(integer variable), where D$ is a string buffer defined using the Field # statement. When I open the file for random and use get to put the data into a string variable the string has characters that cannot be converted back to the original integer using Cint. Any help appreciated

Quick "random Number" Question
If every time a particular button clicked... I need a text field to change to any random number between:

1 and say...10000

Its simple Im sure, but I honestly dont have much experience with VB at all. Thank you in advanced!!

How To Convert From Integer/long Integer To Binary ?
How to convert from integer or long integer to binary in Visual Basic,
for example : 9568 to 10010101100000
and how to convert back from binary to integer or long integer,
for example : 10010101100000 to 9568.

Please help.
dev.

How To Get Msgbox's Static Handle? How To Kill Or Skip Msgbox?
i now know how to send WM_COMMAND into normal buttons.
but i cant send it to a popup msgbox's "OK" button.
the reason is because it's handle keeps on changes everytime it pops up.
so, is there anyway to skip the error msgbox?

Integer Equals Value Of Another Integer
Hi.

I am trying to get intSus be equal to the value of intDown in the following code and I don't know why it won't pass the value on .

Any help would be greatly appreciated

Thanks
Steve


Code:
Dim intDown as integer
Dim intSus as integer
intDown = 1
intSus = 1
Do[indent] Sheets("Sheet3").Select
If Range("A" & intDown).Value = Name1 Then
intSus = intDown '-------- this line doesn't work
Else
intDown = intDown + 1
End If[/indent]Loop Until Range("A" & intDown).Value = Name1

Integer Closest To A Integer
I have a array of 5 variables that are all positive even integers. The integers are anywhere between 0-9. How can I find out which one of those variables less than or equal to a number. The number is Dim'ed as Single.

MsgBox VbSystemModal - How To Show Icon In The Msgbox?
When showing a msgbox as vbsystemmodal, how can you show the apps icon in the msgbox like if a msgbox was shown normally?

The Random Function Gets The Same Random Numbers Every Time I Start The Program
I'm making a Poker program

The code is like:
Command1_click sub()
Card1.caption = int(rnd()*53) +1
Card2.caption = int(rnd()*53) +1
Card3.caption = int(rnd()*53) +1
Card4.caption = int(rnd()*53) +1
Card5.caption = int(rnd()*53) +1
End sub
( I use much more codes of course)

When I click the command1 button, I get the numbers random, but I get the same random numbers in the same order every time I start the game.
Example.

I start the game:
I click command1: card1= 9, card2= 18, card3= 42, card4= 23, card5= 4
I click command1 again: card1= 7, card2= 51, card3= 13, card4= 29, card5= 14
and so on, random every time I click...

I start the game again, another time:
I click command1: card1= 9, card2= 18, card3= 42, card4= 23, card5= 4
I click command1 again: card1= 7, card2= 51, card3= 13, card4= 29, card5= 14
and so on, random every time I click. But I get the same numbers, In the same order.

I hope I've explained my problem well.
Please, help.... =(

Quick Question! Please Answer Quick Easy!!!^*&&^^*&&^&&*^
How the **** do i open the General Tab lol?

See, the giant thing on the left isnt there -_-

http://img214.imageshack.us/img214/3...eraltabbd3.png

Quick Help Sorting A Flexgrid, And Other Quick Question
Hello all, I'm new to this forum, hopefully somebody can help me out with a couple minor problems I have with my code.

I have data inputed into a flexgrid, and would like to sort it by YEAR in increasing order. Year is (frmStats.flexGrid.Col = 0).

The other problem I'm having is that when I try to get a batting average for players or their slugging percentage I get "0" the only time I don't get that is when the number of at bats is 0 then I display ".000", I check for division by zero to stop a run time exectution error. Below is the code you need to help.

Thank you for your help!

blkshirt


Code:
Option Explicit


Type Demo_Record
LahmanID As String * 9
LastName As String * 20
FirstName As String * 15
Bats As String * 1
Throws As String * 1
BirthMonth As Byte
BirthDay As Byte
BirthYear As Integer
RookieSeason As Integer
FirstStatsRecord As Long
StatsRecordPosition As Byte
End Type

Type Stats_In
LahmanID As String * 9
Year As Integer
Team As String * 4
League As String * 4
Games As Integer
AtBats As Integer
Runs As Integer
Hits As Integer
Doubles As Integer
Triples As Integer
HomeRuns As Integer
RBIs As Integer
SacHits As Integer
SacFlies As Integer
Steals As Integer
Caught As Integer
Walks As Integer
Intentional As Integer
HitByPitch As Integer
StrikeOuts As Integer
NextStatsRecord As Long
StatsRecordPosition As Byte
End Type

Type Stats_Block
Stats(1 To 5) As Stats_In
End Type

Type Count_Em_Block
NumStats As Long
x As String * 276
End Type

Global K As String
Global i As Integer
Global J As Integer

Global DemoFileName As String
Global StatsFileName As String

Global DemoRecord As Demo_Record
Global StatsBlock As Stats_Block
Global StatsIn As Stats_In
Global CountBlock As Count_Em_Block
Global PD As Stats_Block

Global Year As Integer
Global Team As String
Global Leauge As String
Global Games As Integer
Global Runs As Integer
Global AtBats As Integer
Global Hits As Integer
Global Doubles As Integer
Global Triples As Integer
Global HomeRuns As Integer
Global RBIs As Integer
Global SacHits As Integer
Global SacFlies As Integer
Global Steals As Integer
Global Caught As Integer
Global Walks As Integer
Global Intentional As Integer
Global HitByPitch As Integer
Global StrikeOuts As Integer

Global CurrentPlayer As Integer
Global NumSeasons As Integer
Global NumPlayers As Integer
Global FullName As String

Global numRecord As Integer
Global ApproxRecords As Long
Global RecsRead As Long
Global StatsRead As Integer
Global StatsRecord As Integer

Global YearRow As Integer
Global TeamRow As Integer
Global LeaugeRow As Integer
Global GamesRow As Integer
Global ABRow As Integer
Global HitRow As Integer
Global DoubleRow As Integer
Global TripleRow As Integer
Global HRRow As Integer
Global RBIRow As Integer
Global SacHRow As Integer
Global SacFRow As Integer
Global StealsRow As Integer
Global WalksRow As Integer
Global HitByRow As Integer
Global KRow As Integer
Global BARow As Integer
Global SPRow As Integer
Global TBRow As Integer
Global SingleRow As Integer
Global BA As Integer
Global SP As Integer
Global TB As Integer
Global firstbase As Integer




'Function used to Calculate a Players Batting Average
Function BatAvg()

If Val(AtBats) = 0 Then
frmStats.lblBA.Caption = ".000"
Else
BatAvg = Round(Val(Hits) / Val(AtBats), 3)
End If

End Function
'Function used to Calculate a Players Total Base Count (Used in Slugging Percentage)
Function TotalBases()
TotalBases = Val(Singles) + Val(Doubles * 2) + Val(Triples * 3) + Val(HomeRuns * 4)
End Function
'Function used to Calculate a Players Slugging Percentage
Function SluggingPct()

If Val(AtBats) = 0 Then
frmStats.lblSP.Caption = ".000"
Else
SluggingPct = Round(Val(TotalBases) / Val(AtBats), 3)
End If

End Function
'Function used to Calculate a Players Total of Singles as it is not given in the data file.
Function Singles()
Singles = Val(Hits) - Val(Doubles) - Val(Triples) - Val(HomeRuns)
End Function
Public Function BinSearch(ByVal Wanted As String, ByVal Lo As Integer, ByVal Up As Integer) As Integer

'*****************************************************
'* Search Function *
'*****************************************************


If Lo > Up Then
BinSearch = False
MsgBox ("Player Not Found")
Else
i = (Lo + Up) / 2

If Left(frmStats.cbo1.List(i), Len(Wanted)) = Wanted Then
BinSearch = True
frmStats.hsbScroll.Value = i
Else
If Left(frmStats.cbo1.List(i), Len(Wanted)) > Wanted Then
BinSearch = BinSearch(Wanted, Lo, i - 1)
Else
BinSearch = BinSearch(Wanted, i + 1, Up)
End If
End If
End If
End Function

Need To Compare Random #s In Listbox With Random #s In Txtbox
Hi all. I'm still trying to work on this lottery program. Now that I have a listbox that randomly lists all the numbers on the user's lotto ticket and made a textbox that randomly picked 6 winning numbers, I need to see if the user won anything. How could I compare random numbers that were both made in a loop? Seems impossible.

Need To Compare Random #s In Listbox With Random #s In Txtbox
Hi all. I'm still trying to work on this lottery program. Now that I have a listbox that randomly lists all the numbers on the user's lotto ticket and made a textbox that randomly picked 6 winning numbers, I need to see if the user won anything. How could I compare random numbers that were both made in a loop? Seems impossible

Change Random # Of Random Bytes In A File
Hey everyone!

I'm testing a CRC program, and I was wondering if anyone has an easy way to change a random number of random bytes in a file.

I assume open it for binary, choose a random number for a loop and then a random number for the byte, but I'm not super clear on the implementation. In otherwords, I think I can figure it out, but I would love some input!

I also want to keep track of which bytes were changed to see if the CRC code not only knows the file changed but which bytes were altered.

Thanks,

Quick Question, Quick Answer!
How do you rename files? I.e. rename C:lah.txt to C:lah.txt2

Converting String To Integer And Integer To String
There are two ways of doing this, but I was wondering which was was more efficient or does it not matter?


VB Code:
Dim sStr As StringDim iInt as Integer 'This works finesStr = 355iInt = "355" 'This also workssStr = Str(355)iInt = Val("355")


Also is there ever a time where you would actually need to use the second method over the first?

Random && Not Random Text Into Textfile
I'm trying to make a program so, when the RUN button that I make is pressed, it outputs text to a text file every 10 seconds. An example of this text is:

admin forceclass 1 ak
admin forceclass 2 rpg
admin forceclass 3 g
etc...
etc...

There are THREE sections to the output though. The "admin forceclass" never changes. The #'s need to start at 1 and increment up to 16 at least. In the 3rd column, I need ONE of the many combinations selected randomly. The letters "ak", "rpg", and "g" all represent guns in the game. There are MORE than just 3 but this was just a small example of the output.

More over .... I want to create a SETTINGS window so that people can SELECT the guns they want to have randomly generated. I play America's Army so this program will allow me to play round after round with my clan mates and just have fun by using random weapons.

I created another topic but I'm not getting ANY feedback on it and would LOVE to get this project going but have been out of VB for a while and have forgotten quite a bit of stuff.


If you have any questions about what I'm trying to make, PLEASE post and ask as I check back often.

I was thinking I'd have to setup an array of some sort for the gun names but I'm not too sure ..... Any help would be GREATLY appreciated!!

THANKS!!

Really Weird, Random Line: Not So Random?
this is extremely unusual. if anyone can explain whats going on in this program in vb i made, id be interested to find out. it makes a random line, one way it does this is with a timer, the other with a for loop. the code is the same for each however, youll see that the results are very different.

Random Password Random Length
I need to be able to generate a password of random alpha and numeric characters and have the password be a random length, but, I want to be able to determine the minimium and maximum length of the password, at random.

Random Game, Trouble With Random.
Hi, we have an assignment at school to create a game which generates a random number and you have to guess what the number is from 1 - 100. The teacher said we had to have hte number in general, something about the program always choosing the same numbers if it was on a button. ifinally figured out how to put it in the general section, and it only picks the same number in the beginning. Everytime you start the game, the number is always either 0 or 1 and most of the time it will stay 0 or 1 until you pick either one of those. Here's the codE:

Option Explicit
' Declares variables holding highest and lowest numbers
Dim HIRAN As Integer
Dim LOWRAN As Integer
' Declares the variable holding the input number
Dim INPUTNUMBER As Integer
' Declares the variable holding the Random number
Dim RANNUM As Integer
' Declares the variables holding the strings
' That appear when you enter a guess
Dim CORRECT As String
Dim TOOHIGH As String
Dim TOOLOW As String
Dim WRONGNUM As String
Dim SECONDWRONGNUM As String
Function Random()
Randomize
RANNUM = ((HIRAN - LOWRAN + 1) * Rnd + LOWRAN)
End Function

Public Sub CmdCheck_Click()
' Makes the highest number 99 and lowest number 1
HIRAN = 100
LOWRAN = 1
' Changes the variables to the statements that
' appear as hints
CORRECT = "CORRECT!"
TOOHIGH = "High"
TOOLOW = "Low"
WRONGNUM = "That's higher than 99!"
SECONDWRONGNUM = "That's Lower than 1..."
' Makes the variable INPUTNUMBER hold the number
' entered by the user
INPUTNUMBER = txtInput.Text
' Displays a hint saying that the entered number
' is higher than 100
If INPUTNUMBER > 100 Then
MsgBox (WRONGNUM)
' Displays a hint saying that the entered number
' is lower than 1
ElseIf INPUTNUMBER < 1 Then
MsgBox (SECONDWRONGNUM)
' Informs the user they entered the correct number
' when the number they entered is equal to
' the random number
ElseIf INPUTNUMBER = RANNUM Then
lblHiLow.Caption = CORRECT
' Informs the user when they enter a number that
' is higher than the random number
ElseIf INPUTNUMBER > RANNUM Then
lblHiLow.Caption = TOOHIGH
' Informs the user when they enter a number that
' is lower than the random number
ElseIf INPUTNUMBER < RANNUM Then
lblHiLow.Caption = TOOLOW
End If
End Sub
' Ends the program when Quit button is clicked
Private Sub CmdQuit_Click()
Unload Me
End
End Sub
' Starts the Function Random
Private Sub CmdStartgame_Click()
Call Random
CmdCheck.Visible = True
lblHiLow.Visible = True
lblInstructions.Visible = True
txtInput.Visible = True
Print RANNUM
End Sub

So basically I just need help to make it start off with a truely random number rather than 1 or 0. what I did is I made a button to make the computer choose a new number everytime the button is clicked, and a seperate button to change the variable holding the Input number.
I'm also having a problem changing the color of a command button, I changed every possible drop down color changing menu, but nothing happens at all, and I"m running vb 5 CCE.
Thanks

Random Game - Trouble With Random
Hi, we have an assignment at school to create a game which generates a random number and you have to guess what the number is from 1 - 100. The teacher said we had to have hte number in general, something about the program always choosing the same numbers if it was on a button. ifinally figured out how to put it in the general section, and it only picks the same number in the beginning. Everytime you start the game, the number is always either 0 or 1 and most of the time it will stay 0 or 1 until you pick either one of those. Here's the codE:

Option Explicit
' Declares variables holding highest and lowest numbers
Dim HIRAN As Integer
Dim LOWRAN As Integer
' Declares the variable holding the input number
Dim INPUTNUMBER As Integer
' Declares the variable holding the Random number
Dim RANNUM As Integer
' Declares the variables holding the strings
' That appear when you enter a guess
Dim CORRECT As String
Dim TOOHIGH As String
Dim TOOLOW As String
Dim WRONGNUM As String
Dim SECONDWRONGNUM As String
Function Random()
Randomize
RANNUM = ((HIRAN - LOWRAN + 1) * Rnd + LOWRAN)
End Function

Public Sub CmdCheck_Click()
' Makes the highest number 99 and lowest number 1
HIRAN = 100
LOWRAN = 1
' Changes the variables to the statements that
' appear as hints
CORRECT = "CORRECT!"
TOOHIGH = "High"
TOOLOW = "Low"
WRONGNUM = "That's higher than 99!"
SECONDWRONGNUM = "That's Lower than 1..."
' Makes the variable INPUTNUMBER hold the number
' entered by the user
INPUTNUMBER = txtInput.Text
' Displays a hint saying that the entered number
' is higher than 100
If INPUTNUMBER > 100 Then
MsgBox (WRONGNUM)
' Displays a hint saying that the entered number
' is lower than 1
ElseIf INPUTNUMBER < 1 Then
MsgBox (SECONDWRONGNUM)
' Informs the user they entered the correct number
' when the number they entered is equal to
' the random number
ElseIf INPUTNUMBER = RANNUM Then
lblHiLow.Caption = CORRECT
' Informs the user when they enter a number that
' is higher than the random number
ElseIf INPUTNUMBER > RANNUM Then
lblHiLow.Caption = TOOHIGH
' Informs the user when they enter a number that
' is lower than the random number
ElseIf INPUTNUMBER < RANNUM Then
lblHiLow.Caption = TOOLOW
End If
End Sub
' Ends the program when Quit button is clicked
Private Sub CmdQuit_Click()
Unload Me
End
End Sub
' Starts the Function Random
Private Sub CmdStartgame_Click()
Call Random
CmdCheck.Visible = True
lblHiLow.Visible = True
lblInstructions.Visible = True
txtInput.Visible = True
Print RANNUM
End Sub

So basically I just need help to make it start off with a truely random number rather than 1 or 0. what I did is I made a button to make the computer choose a new number everytime the button is clicked, and a seperate button to change the variable holding the Input number.
I'm also having a problem changing the color of a command button, I changed every possible drop down color changing menu, but nothing happens at all, and I"m running vb 5 CCE, and school running vb 5 enterprise edition.
Thanks

Random Numbers Not So Random?
Code:
Public Function Random(MaxValue As Long) As Long
Randomize
Random = Rnd() * (MaxValue - 1) + 1
End Function
Now, this *should* give a random number between 1 and MaxValue, right?

Eh. Not quite. When I call this function, it delivers a random which appears random, but in actuality, differs very little each time the program is run.

To see what I'm talking about, download SpriteWars.zip from my recent post 'Classes: What a pain'. Notice that while the starting position of all the marines is different each time the program is run, they're always in several long lines, going down and to the left.

Is my Random() function not so random after all? =P

Any help?

NOT Random Random Numbers
Hello,

I'm currently coding a random multi choice quiz for Uni, however the Rnd function in VB seems much less than random!

Is there a better function or some code to make it less predictiable?

Cheers

Neil

Random Number - Not So Random
I've been using the fairly standard:

intNumb = Int(Rnd * 100) + 1

to select a random integer between 1 and 100, inclusive. But I've
noticed that it's not random. If I run the program twice in a row I get the same number - over and over. I reset intNumb to zero after every use - still no luck.

How does Rnd work? Never had this problem with C, Java, etc...

Thanks in advance

Random Numbers Not Actually Being Random
Edit by Moderator: Start your own threads please.
How would you take an input from the user, n. And create n random numbers?

I've got this code for my input box...

Private Sub Text1_Change()
Dim num As Single
num = Val(Text1.Text)
End Sub

Then I've got a button, which once pressed I want n random numbers generated. These numbers don't need to be displayed as I want to sort them into 10 categories...

What would be the code I'd need for my button??
I've got so far...

Private Sub Command1_Click()
Randomize
num = Rnd
End Sub

I don't think though that my code will generate n random numbers... or will it?

Random Numbers Not Actually Being Random
I'm trying to generate a random number between 1 and 15 for a case select. Here's what I've got:


Code:
Random = CInt(Int((15 * Rnd()) + 1))
This does generate numbers between 1 and 15, but the order isn't random! I run the program and get the exact same number of each case in the exact same order every time. What am I doing wrong?

Copyright 2005-08 www.BigResource.com, All rights reserved