Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 12-05-2006, 08:50 PM   #1 (permalink)
jesspren6's Avatar
 
Super Techie

Join Date: May 2006

Posts: 266

jesspren6 is on a distinguished road

Default random buttons in VB

I'm making a simple program that there are many command buttons with numbers on them. I want the program to choose a random button each time the program is opened. Then when the person guesses the right button, it will take it to another form. I know how to make it go to another form, but i do need help on how it will choose a random number each time the program is opened.
jesspren6 is offline  
Old 12-05-2006, 11:20 PM   #2 (permalink)
 
Super Techie

Join Date: Oct 2006

Posts: 263

penfold

Default

I'm not sure what he used to make his, or if *he* was the one who did it, but the man at http://www.ghisler.com used what appears to be this technique in his software "Total Commander" for the unregistered version. Maybe you could get in touch with him?
__________________
---
penfold

www.futurelooks.com/
www.megatechnews.com
penfold is offline  
Old 12-06-2006, 07:10 AM   #3 (permalink)
baronvongogo's Avatar
 
Master Techie

Join Date: May 2005

Location: UK

Posts: 2,749

baronvongogo is on a distinguished road

Default

http://msdn2.microsoft.com/en-us/library/f7s023d2.aspx

Its been ages since iv done VB but that link above would be a good starting point and looking on google i found a few sites with examples but i`ll let you do that your self . I think basically you would have each button with an index and use that as the rnd instead of numbers so it`ll randomise between say 6 buttons and maybe a variable for when its chosen to be set to 1 or something...and then do an if statement to say if button 1 = true open form etc.

god i need to brush up on my programming me thinks
__________________
baronvongogo is offline  
Old 12-06-2006, 09:15 AM   #4 (permalink)
 
Ultra Techie

Join Date: Jul 2006

Posts: 714

Meithan is on a distinguished road

Send a message via AIM to Meithan Send a message via Yahoo to Meithan
Default

If the buttons are always the same, but what changes is which is the correct button to push, then it's very simple (the last post almost gave it away): when the form opens, randomize an integer (from 1 to the number of buttons you want). Then, just assign a number (in your head) to each button and put a check in the button's code: if the random number matches the preset number for that button, then you go to the next form.

On Form load:
Randomize()
RndNum = Int(Rnd() * n + 1) //where "n" is th number of buttons

Buttons:
Button1_Click: "If RndNum=1 Then form2.show"
Button2_Click: "If RndNum=2 Then form2.show"
etc...

Since the correct button is fixed, all he'll have to do is click them all until one works (rather silly). If you want to randomize the buttons again after he makes a try (so he really has to guess), just put the RndNum = Int(Rnd() * n + 1) line in the code of each button before the check.

Hope this helps.

Edit: by the way, are you using VB6 or VB.NET (or even DOS Basic)?
__________________


SuperPi 1M: 29.6s - 3DMark06: 8616
The Geek Test v3.1 Score: 36.3% - Major Geek
Meithan is offline  
Old 12-06-2006, 09:41 AM   #5 (permalink)
baronvongogo's Avatar
 
Master Techie

Join Date: May 2005

Location: UK

Posts: 2,749

baronvongogo is on a distinguished road

Default

good stuff Meithan I just did that in visual studio and it worked like a charm I new i was on the right track somewhere it should help out jesspren6 no problem.

I forgot how nice VB is to code and use although c# is just as nice.
__________________
baronvongogo is offline  
Old 12-06-2006, 10:36 AM   #6 (permalink)
 
Ultra Techie

Join Date: Jul 2006

Posts: 714

Meithan is on a distinguished road

Send a message via AIM to Meithan Send a message via Yahoo to Meithan
Default

Yeah, Visual Basic is a breeze. I know C++ is more powerful, but for small, quick Windows apps, I think there's nothing like Visual Studio 2005. I absolutely love it. I'm a VB6 user migrating from Visual Studio 6, and boy are there nice new features! It makes placing controls and such on your form very quick (and it looks nice, too!), so you can concentrate on the code.

Still waiting for jesspren6 to reply...
__________________


SuperPi 1M: 29.6s - 3DMark06: 8616
The Geek Test v3.1 Score: 36.3% - Major Geek
Meithan is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On