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.
5 1397
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.
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: - Select Case KeyCode
-
Case vbKeyEscape
-
End
-
GO.Visible = False
-
Case vbKeyLeft
-
G_Ship.Left = (G_Ship.Left - 18)
-
Case vbKeyRight
-
GO.Visible = False
-
G_Ship.Left = (G_Ship.Left + 18)
-
Case vbKeyUp
-
GO.Visible = False
-
G_Ship.Top = (G_Ship.Top - 18)
-
Case vbKeyDown
-
GO.Visible = False
-
G_Ship.Top = (G_Ship.Top + 18)
-
End Select
If so is their something I should put as the case. If not can you give me an example?
When you say that do you mean something like this: - Select Case KeyCode
-
Case vbKeyEscape
-
End
-
GO.Visible = False
-
...
-
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... - MyNumber = RND * 4 ' <-- Probably not quite correct.
-
Select Case MyNumber
-
Case 1
-
Do function 1
-
Case 2
-
Do function 2
-
Case 3
-
Do function 3
-
Case 4 ' Or "Case Else"
-
Do function 4
-
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.
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... - MyNumber = RND * 4 ' <-- Probably not quite correct.
-
Select Case MyNumber
-
Case 1
-
Do function 1
-
Case 2
-
Do function 2
-
Case 3
-
Do function 3
-
Case 4 ' Or "Case Else"
-
Do function 4
-
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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;
}
|
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
|
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...
|
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...
|
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
| |
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...
|
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...
|
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.
...
|
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
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |