473,378 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Random function 1 - 4

I need to create a random code to run a function 1 - 4. i.e. random number is 1 so it runs function 1 random number is 2 so it runs function 2. I would like to have this in VBA because that is all I have.

Thanks for your support.
Apr 3 '07 #1
5 1387
Killer42
8,435 Expert 8TB
I need to create a random code to run a function 1 - 4. i.e. random number is 1 so it runs function 1 random number is 2 so it runs function 2. I would like to have this in VBA because that is all I have.
Generate a value into a variable using the rnd function, then use Select Case to make the decision.
Apr 3 '07 #2
Generate a value into a variable using the rnd function, then use Select Case to make the decision.
When you say that do you mean something like this:

Expand|Select|Wrap|Line Numbers
  1. Select Case KeyCode
  2. Case vbKeyEscape
  3.     End
  4.     GO.Visible = False
  5. Case vbKeyLeft
  6.     G_Ship.Left = (G_Ship.Left - 18)
  7. Case vbKeyRight
  8.     GO.Visible = False
  9.     G_Ship.Left = (G_Ship.Left + 18)
  10. Case vbKeyUp
  11.     GO.Visible = False
  12.     G_Ship.Top = (G_Ship.Top - 18)
  13. Case vbKeyDown
  14.     GO.Visible = False
  15.     G_Ship.Top = (G_Ship.Top + 18)
  16. End Select
If so is their something I should put as the case. If not can you give me an example?
Apr 3 '07 #3
Killer42
8,435 Expert 8TB
When you say that do you mean something like this:
Expand|Select|Wrap|Line Numbers
  1. Select Case KeyCode
  2. Case vbKeyEscape
  3.     End
  4.     GO.Visible = False
  5. ...
  6. End Select
If so is their something I should put as the case. If not can you give me an example?
You said that you needed to "create a random code to run a function", not use a keypress. What I was suggesting was something like...
Expand|Select|Wrap|Line Numbers
  1. MyNumber = RND * 4 ' <-- Probably not quite correct.
  2. Select Case MyNumber
  3.   Case 1
  4.     Do function 1
  5.   Case 2
  6.     Do function 2
  7.   Case 3
  8.     Do function 3
  9.   Case 4 ' Or "Case Else"
  10.     Do function 4
  11. End Select
By the way, any statement following the End statement, such as the one I highlighted above, will not be executed. End causes the program to end immediately.
Apr 3 '07 #4
You said that you needed to "create a random code to run a function", not use a keypress. What I was suggesting was something like...
Expand|Select|Wrap|Line Numbers
  1. MyNumber = RND * 4 ' <-- Probably not quite correct.
  2. Select Case MyNumber
  3.   Case 1
  4.     Do function 1
  5.   Case 2
  6.     Do function 2
  7.   Case 3
  8.     Do function 3
  9.   Case 4 ' Or "Case Else"
  10.     Do function 4
  11. End Select
By the way, any statement following the End statement, such as the one I highlighted above, will not be executed. End causes the program to end immediately.
I understand I was asking about how to do the case. I will be sure to take your example into consideration.
Apr 3 '07 #5
Killer42
8,435 Expert 8TB
I understand I was asking about how to do the case. I will be sure to take your example into consideration.
Cool.

Hope it works out.
Apr 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: JNY | last post by:
I am using random to generate random numbers, thus: int x,y; for (y = 0;y < 5;y++) { x = random(50); cout << x; }
3
by: TaTonka | last post by:
hi! how can i manage it (html or jscript with css) that everytime a user loads or refreshes a page, the page has a new bgcolor. i want to put it in a single file, so that all my pages have the...
4
by: Greg Strong | last post by:
Hello All, Is it possible to create multiple random numbers in a query where there are numerous records? I've created a custom function. When I use it in a query it creates the same random...
13
by: Jon Agiato | last post by:
Hello, I am sure this problem is easy to spot but I have been at this project all day and the frustration has finally overcome me. I am using this function in order to produce a standard normal...
10
by: Leon | last post by:
I know by default the random number generator use the time, but what is the best seed I can used in my web application? The Program generate 6 unique random numbers and load each of them in a...
3
by: JoelPJustice | last post by:
I am working through a VBA book by myself to help and try and improve my skills. However, the book does not give you solutions to certain problems. I have worked through this problem up until bullet...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I generate a random integer from 1 to N?...
3
by: tshad | last post by:
I have a page that I am getting a username and password as a random number (2 letters, one number and 4 more letters) I have 2 functions I call: *************************************************...
0
by: UmeIsmail | last post by:
i am trying to implement GP , and have random initialization in arraylist , the code works fine in debug mode , but when i run it without debugging, all trees come out to be same , if i use message...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.