Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


vb6 how to

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
coder sal
Master Cheater
Reputation: 0

Joined: 11 May 2007
Posts: 304

PostPosted: Sat Nov 10, 2007 3:33 pm    Post subject: vb6 how to Reply with quote

How do you generate random numbers in VB6?
Back to top
View user's profile Send private message
AtheistCrusader
Grandmaster Cheater
Reputation: 6

Joined: 23 Sep 2006
Posts: 681

PostPosted: Sat Nov 10, 2007 3:34 pm    Post subject: Reply with quote

msgbox Rnd(Val(rnd * 100 + 1)
if u want exact
Back to top
View user's profile Send private message
coder sal
Master Cheater
Reputation: 0

Joined: 11 May 2007
Posts: 304

PostPosted: Sat Nov 10, 2007 3:37 pm    Post subject: Reply with quote

syntax error...
Back to top
View user's profile Send private message
AtheistCrusader
Grandmaster Cheater
Reputation: 6

Joined: 23 Sep 2006
Posts: 681

PostPosted: Sat Nov 10, 2007 3:38 pm    Post subject: Reply with quote

msgbox (Rnd(Val(rnd * 100 + 1) )

try this 1
Back to top
View user's profile Send private message
coder sal
Master Cheater
Reputation: 0

Joined: 11 May 2007
Posts: 304

PostPosted: Sat Nov 10, 2007 3:40 pm    Post subject: Reply with quote

Still syntax error...I got the code its MsgBox (Rnd * 100 + 1) without the other shit. Thnx, I did Text1.Text = (Rnd * 100000) but why is it always a decimal number wtf?

Last edited by coder sal on Sat Nov 10, 2007 3:43 pm; edited 1 time in total
Back to top
View user's profile Send private message
AtheistCrusader
Grandmaster Cheater
Reputation: 6

Joined: 23 Sep 2006
Posts: 681

PostPosted: Sat Nov 10, 2007 3:42 pm    Post subject: Reply with quote

the thing was i added Val to rnd without puttin another ) in the end
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Nov 10, 2007 4:52 pm    Post subject: Reply with quote

You should also make a call to Randomize to have a more random output:

Code:
Private Sub Command1_Click()
    Randomize
    MsgBox CLng(Rnd * 255)
End Sub


You can also setup a seed with Randomize which will help 'randomize' the output generated from Rnd.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
XxOsirisxX
Grandmaster Cheater Supreme
Reputation: 0

Joined: 30 Oct 2006
Posts: 1597

PostPosted: Sat Nov 10, 2007 9:00 pm    Post subject: Reply with quote

Wiccaan wrote:
You should also make a call to Randomize to have a more random output:

Code:
Private Sub Command1_Click()
    Randomize
    MsgBox CLng(Rnd * 255)
End Sub


You can also setup a seed with Randomize which will help 'randomize' the output generated from Rnd.


This one is good, also will be an "Integer" number because the CLng (Convert to long). That will generate a "random" number between 0~255, I realy don't know if negatives are allowed, i suppose no.

In another hand, i will gave you this code in case you wish to use a defined randoms values.

Quote:
Public Function Rand(ByVal Low As Long, ByVal High As Long) As Long
Rand = Int((High - Low + 1) * Rnd) + Low
End Function


After having Rand as public then you just add this as example..

Quote:
Randomize

blablabla = Rand(1, 2)
if blablabla = 1 then
msgbox "123"
....


So, you put the Lowest and Higher numbers you wants to be "random" between. In this case, where between 1 and 2.

Hopes you undersntad it, and if will not use, at least learn something which is better.

_________________

Back to top
View user's profile Send private message
Golden Wing
Grandmaster Cheater
Reputation: 0

Joined: 29 Aug 2007
Posts: 905

PostPosted: Sat Nov 10, 2007 9:25 pm    Post subject: Reply with quote

crap wiccaan and XxOsirisxX beat me to it
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Nov 11, 2007 6:52 am    Post subject: Reply with quote

XxOsirisxX wrote:
That will generate a "random" number between 0~255, I realy don't know if negatives are allowed, i suppose no.


Negative numbers work.

Also in your code, you should call Randomize as well.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
TheLazyCat
Expert Cheater
Reputation: 0

Joined: 29 Sep 2007
Posts: 117
Location: My House with Milk

PostPosted: Wed Nov 14, 2007 8:18 pm    Post subject: Reply with quote

The easiest would be
Code:

Randomize

textbox1.text = Int(Rnd() * 100) ' for the textbox1.text but whatever the output box is


the * 100 means its a random number 0-99 you can change that
if you put
[/code]textbox1.text = int(Rnd() * 100 + 1)
Code:

then it would be 1-100 {I think im not certain}
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites