How to execute simultaneous lines of code in VBA?

I have 3 equations I would like to execute simultaneously.  Please show me how to execute simultaneous equations in VBA.

NP1 = (NPmax1 * Rnd() + NPmin1)
NP2 = (NPmax2 * Rnd() + NPmin2)
NP3 = (NPmax3 * Rnd() + NPmin3)

This is an urgent one...

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Harisha M GEngineerCommented:
Hi, if your goal is to use the same random value for all the three, then you need to store that in some temporary variable

TemporaryVar = Rnd()
NP1 = (NPmax1 * TemporaryVar + NPmin1)
NP2 = (NPmax2 * TemporaryVar + NPmin2)
NP3 = (NPmax3 * TemporaryVar + NPmin3)

Patrick MatthewsCommented:
Hi rgrguric,

Why is it important that these be done at the same time?

Also, if the intent is to make NP1 be a randomly selected value between NPmin1 and NPmax1, your code does not
necessarily achieve it.  This will:

NP1 = NPmin1 + (NPmax1 - NPmin1) * Rnd()


rgrguricAuthor Commented:
I need it to calculate a different random value for each equation.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Muhammad KhanManager, ITCommented:
but why simultaneous?
rgrguricAuthor Commented:
I have many equations similar to these that would save me a bunch of time if I could run them simultaneously... I'm using this for data analysis.  I have 78 variables involved in a set of 83 equations.  I need to run that set of 83 equations 500,000 times... this is very time consuming running each line one by one.
Harisha M GEngineerCommented:
rgrguric, can you tell us, what exactly is your need ?

What do you mean by executing simultaneously ?

1) Do you mean they are simultaneous equations ?
-- If so, store the coeffecients, and then use one of the methods, (matrix method, using determinant would be the easiest) to solve them

2) Do you mean they should be executed at the same time ?
-- I am not aware of that in VB without a new thread
rgrguricAuthor Commented:
Thank you for the correct random function Patrick.
Muhammad KhanManager, ITCommented:
VB doesnt support multithreading intrinsincly...

but you can still create ActiveX Exes and have them run simultaneaously from an application. but that would be a poor design...

rgrguricAuthor Commented:
I enter 13 nominal values for 6 variables.  I then calculate the min and max for each nominal value. Next, I generate a random number between the min and max.  I then have 78 "random" numbers.  I then use these "random" numbers in various equations.  Finally, I store the results.  I recalculate the "random" numbers and rerun the various equations each iteration.

The problem I run into is when i run 1,000 iterations, time ran < 1min
When I run 10,000 iterations, time ran < 2min
When I run 100,000 iterations, time ran > 30 min... I stopped at 30 min, there were only 23k out of 100k records stored in the table
Muhammad KhanManager, ITCommented:
Then i can suggest that you design an ActiveX Exe project.. which does all the calculation and then insert the data into database.. then you create 6 objects and have those running... Threading model must be per object... so that every object runs in a separate thread...

theoritically that should reduce the time of execution to 1/6th of present value.
Harisha M GEngineerCommented:
Instead of storing/displaying the results in each iteration, store them in some temporary variable, and store to the table/display it after some, say 100, iterations. This will speed up the process...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Muhammad KhanManager, ITCommented:
Oh my god... i h ave just noticed that you want to do that in VBA.... so sorry... i overlooked at that...
I must be more careful while reading the Questions.. :(
what you are describing is generally called "PARALLEL PROCESSING" - and ANY version of VB (VB6 or VB.NET) is a very poor choice for attempting to do 'parallel processing'

Parrallel processing generally involves using Multiple preocessor 'threads' to carry out the 'simultaneous' calculations, and as said, earlier, VB is not well suited for doing multi-threaded applications.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.