Need some help with randomizing
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts
Page 1 of 1
I have 5 Functions setup and I want to randomize what one is triggered when any key is pressed on a keyboard.
Any assistance would be appreciated.
Any assistance would be appreciated.
A simple random with a select may do the job.
On your keydown or keypress event (whatever you're using) do something like:
On your keydown or keypress event (whatever you're using) do something like:
Code: Select all
Dim r As New Random
Select Case r.Next(0, 5)
Case 0
function1
Case 1
function2
Case 2
function3
Case 3
function4
Case 4
function5
End Select
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Thanks I forgot all about using a case statement. Now I just need to get the background music to keep playing when the other sounds play.
Other then that this works great. It is an application that I am making for my 11 month old so he can smack the keyboard on an old netbook and have fun with animals popping up and making sounds.
So if anyone knows how to get the sound to work correctly I would love an answer as I have been unable to find an answer.
Other then that this works great. It is an application that I am making for my 11 month old so he can smack the keyboard on an old netbook and have fun with animals popping up and making sounds.
So if anyone knows how to get the sound to work correctly I would love an answer as I have been unable to find an answer.
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023