dice games

chrlshrdy
15 Oct 2003, 05:53
I need help. I'm trying to make a dice game in VB 6.0 as my first VB program so I need LOTS of help lol... I figured out how to make a splash screen and an about screen, but that's about all I could figure out... the rest is "greek" to me.

kewldude606
16 Oct 2003, 01:41
For getting a random number in VB:
Dim Done As Boolean
Done = False
Randomize
While Done = False
RandomNumber = Int(Rnd(1) * 10)
If RandomNumber > 0 And RandomNumber < 7 Then Done = True
Wend


I'm sure theres a more effiect way to do this...
The Randomize makes VB base the random number off the time and date instead of using it's built-in list.

Alex
16 Oct 2003, 08:20
Of course there's a more efficient way - you're choosing a number between 0 and 10 and rejecting it if it's not between 1 and 6.... why? Also when you're using a While..Wend loop, there's really no need for the "Done" boolean as you can just put an equivalent condition in "While". Anyway the loop is completely pointless as you can use this to choose a number between 1 and 6:

Dim RandomNumber as Integer
RandomNumber = Int(Rnd*6)+1

Anonymous
25 Oct 2003, 06:51
I noticed all the different ways in here to get a randomized number and, being a hobbiest VB 6 programmer, know the bestway to get a random number: Type this:


Private Sub Form_Load()
Randomize
End Sub

Private Sub Command1_Click()
Dim rndNumber As Single
Dim number As Integer

rndNumber = Rnd
number = Int(x * rndNumber + 0.9999) 'where x is the maximum number
End Sub


This is easily the fasted and best way to get a random number that I know. Hope I could lend a hand,

8) Matthew G. 8)

paul_one
25 Oct 2003, 15:32
how is assigning a random number to a variable and then using that in the equation faster than using the rnd function in the equation itself.

Also why are you using 0.9999? To allow the generation of the 0 number?
Surely if you wanted the generation of the 0 number you'd simply add one onto the X number.

The fastest way to get a random number is surely rnd :) ... But to get a random number from 0 to a number is int(rnd * (number + 1)). While from 1 to the number would be int((rnd * number) + 1).

And from number x to number y is: int(rnd * (y - x + 1) + x)...

codingmasters
28 Oct 2003, 06:56
For ur information, I use the 0.9999 so that the random numbers are all proper integers. Without that, the numbers would have stacks of decimal places tacked on the end.

Also, I am unfamiliar with the 'Int' so if you would like to brief me on that please do so

Matthew G.

paul_one
28 Oct 2003, 10:46
The 0.9999 would add digits onto the end:
rnd (should) generate a number between 0.000 and 0.999 ... Let's give an example:

rnd = 0.236
+ 0.9999
= 1.2359

Int just cut's off all the numbers after the decimal point;
number = 2.736
int(number) = 2

codingmasters
29 Oct 2003, 00:03
But that still doesn't tell me how to use the Int function

Matthew G.

paul_one
29 Oct 2003, 04:32
You type int(3 * 3.5) and you get 10... NOT 10.5, just 10.

That is what the int function *IS*. If you were a hobbyist VB programmer you'd know this!

codingmasters
29 Oct 2003, 06:33
1. How does that generate a random number? To me it looks as though it's a function that does sums. That's all

2. The book that I learnt from did not teach me about the Int function

Matthew G.

I think Im Dead
29 Oct 2003, 07:41
I know nothing of vb but I'm going to take a guess and say it has something to do with that mysterious 'rnd' mentioned earlier.

paul_one
29 Oct 2003, 15:40
I've already explained what the "int()" function does. It just takes the pure integer's from the numbers inside the ()'s.

You use the Int function yourself in your example - just like the rnd function.

And you're quite right ITID - rnd() generates a number from 0.000 to 0.999 - which AGAIN I've already explained.

If you haven't even learnt what the int() or rnd() functions do then actually get yourself a proper book, you must have been reading from a rough note-book with one page in it.

codingmasters
30 Oct 2003, 05:32
Wrong

You never explained the Int function.

Oh, and don't start flaming, or this will be about the fourth topic Alex will have locked and he doesn't want to have to do it again.

And by the way, I didn't learn from a "rough note-book with one page."
I learn't from a very well-known series of books called Complete Idiots Guides. And if one person says i'm a complete idiot i'll ask alex to lock this topic myself

Matthew G.

Anonymous
30 Oct 2003, 08:44


I learn't from a very well-known series of books called Complete Idiots Guides



I'm not really a fan of the 'for Dummies' & 'Complete Idiot's' guide books, I would recommend getting/borrowing a copy of the SAMS "Teach Yourself in 21 days" series books (& the follow ups) if you want a VB primer. They're not so light a read, but considerably more useful.

Al
(a.k.a. MaDbRiT)

Anonymous
30 Oct 2003, 08:47
Oh yeah...

I now have my web server access back :D - so I will post an updated copy of my typelib library on my website later this week.

There is no up to date documentation for it as yet, but do look to make sure you have a recent version before downloading - the old one is still there at present.

Al

(a.k.a. MaDbRiT)

paul_one
30 Oct 2003, 14:31
Posted on: Tue 28 Oct, 2003 10:46 am

Int just cut's off all the numbers after the decimal point


How is this NOT telling you what the int function does?

Alex would lock this forum because I said "I've already told you how the int function works" and "you learnt from a notebook" in a mildly serious tone? I wouldn't expect him to since it hasn't got violent and I'm not truely insulting you.

I'd be surprised if the "idiot's guide to VB" or whatver didn't mention the int() function. Somewhere in there should be a mathematical equation with int(). ESPECIALLY in the random number generation section. If that book doesn't have anything to do with random numbers then either it's been ripped out or someone wrote "idiot's guide to VB" on the front of a scrap book and sold it to you for an outrageous price.

Oh, BTW Al - that's cool you'll be releasing the new typelib - I'll be looking foreward to taking a peek under the bonet (even though I don't actually use it).

EDIT:
And Al, those 21 day books, have you read any of them? Would they actually take 21 days to learn that stuff? Does it mean 21 FULL days or 21 evenings or what? I personally haven't used a book to learn to do anything so :P .

Anonymous
30 Oct 2003, 16:11


And Al, those 21 day books, have you read any of them? Would they actually take 21 days to learn that stuff? Does it mean 21 FULL days or 21 evenings or what?



The books are supposed to be 21 daily lessons. :-)

Depending on your start point, if you already know how to program and are looking to find out how to use VB as an alternative language you might whizz through these books in a few days taking several 'lessons' at a time, but if you're starting from scratch it's going to take a LOT longer and each lesson probably needs a days worth of attention and practicing what's taught.

I think the 21 days is just a catchy alternative title for what is more accurately :-
"A basic course in VB arranged as 21 lessons - take them at your own pace".

The more accurate description doesn't exactly trip off the tongue does it?

Strangely the hardbacked "Professional Reference" version of the book that I have (I learned VB back when it was VB3, but bought the book(s) when VB5 came out) actually has 28 days worth of lessons (a bonus week they call it) which is odd in a book claiming to teach you in 21 days... :D

There's a follow up 21 day book on more advanced topics too.

Al

(MaDbRiT)

GameBoy
30 Oct 2003, 16:56
what in the hell happened to this thread? lol

codingmasters
30 Oct 2003, 18:38
Iwould also like to know what happened to this thread.

CW, after the way u went on up there Alex will lock it!
And by the way, there was norandom number generation section, i customized the code to fit my own needs from a sample program in there

Matthew G.

paul_one
30 Oct 2003, 22:48
If it's in the sample program it should be in the booklet - infact, I have never known it to be in a sample program and NOT in the book.

codingmasters
31 Oct 2003, 00:15
OK. What I meant is that my book doesn't cover random number generation. It covers a timer script which makes a button move across the screen. In this sample program is the random number generation code

Matthew G.