473,763 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random function 1 - 4

44 New Member
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 1397
Killer42
8,435 Recognized Expert Expert
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
I Hate My Computer
44 New Member
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 Recognized Expert Expert
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
I Hate My Computer
44 New Member
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 Recognized Expert Expert
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
2982
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
5029
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 same color, but after every refresh a new random one. thanx 4 your support
4
8249
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 number for ALL the records. It appears the function is only getting called once, therefore only one random number is being generated for all the records. I want a different random number for each record. Is this possible, or do I have to do it all...
13
3616
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 distribution random number generator and then using the function in another part of my program in order to use the value. This function is called for many iterations. The problem is, through each run I am getting the exact same number generated...
10
2677
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 textbox control. I need a good seed like ip address or something. 'Function to generate random numbers Public Function GetRandomNumber() As Integer
3
24548
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 point 3. Here is the code I came up with up until now. Function RandomNormal(Mean As Double, StdDev As Double) As Double Application.Volatile Randomize RandomNormal = (StdDev * Sqr(-2 * Log(Rnd)) * Cos(2 * 3.141596 * Rnd)) + Mean End...
12
3229
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 without success. for example if the number is 123 456 : i would like to have some random strings like theese : (12 * 10 000) + (345 * 10) + (6*1) or (123*1 000)+(4*100)+(5*10)+(6*1) etc...
1
338
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I generate a random integer from 1 to N? ----------------------------------------------------------------------- function Random(x) { return Math.floor(x*Math.random()) } gives a random integer in the range from 0 to x-1 inclusive; use « Random(N)+1 » for 1 to N where N>2. ...
3
2083
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: ************************************************* Function RandomString(size as integer, lowerCase as boolean) as string Dim builder as StringBuilder = new StringBuilder() Dim random as Random = new Random() Dim i as integer dim ch as char
0
841
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 box to show these trees , code works fine again ... i have become MAD in resolving this issue !! create_rndtree(ref al,depth) create_fixtree(ref al,depth); trees are stored in al array of arralist , which is cleared first below is the code...
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9828
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8825
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7370
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5271
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3918
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3529
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.