Link to home
Create AccountLog in
Avatar of rgrguric
rgrguric

asked on

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...

Thanks,
Avatar of Harisha M G
Harisha M G
Flag of India image

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)


---
Harish
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()

Regards,

Patrick
Avatar of rgrguric
rgrguric

ASKER

I need it to calculate a different random value for each equation.
but why simultaneous?
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.
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
Thank you for the correct random function Patrick.
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...

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
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.
ASKER CERTIFIED SOLUTION
Avatar of Harisha M G
Harisha M G
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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.

AW