[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to execute simultaneous lines of code in VBA?

Posted on 2006-04-03
13
Medium Priority
?
809 Views
Last Modified: 2010-04-07
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,
0
Comment
Question by:rgrguric
  • 4
  • 4
  • 3
  • +2
13 Comments
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16363693
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
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 16363715
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
0
 

Author Comment

by:rgrguric
ID: 16363728
I need it to calculate a different random value for each equation.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 17

Expert Comment

by:Muhammad Khan
ID: 16363746
but why simultaneous?
0
 

Author Comment

by:rgrguric
ID: 16363754
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.
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16363764
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
0
 

Author Comment

by:rgrguric
ID: 16363768
Thank you for the correct random function Patrick.
0
 
LVL 17

Expert Comment

by:Muhammad Khan
ID: 16363862
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...

0
 

Author Comment

by:rgrguric
ID: 16363868
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
0
 
LVL 17

Expert Comment

by:Muhammad Khan
ID: 16363923
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.
0
 
LVL 37

Accepted Solution

by:
Harisha M G earned 1500 total points
ID: 16363928
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...
0
 
LVL 17

Expert Comment

by:Muhammad Khan
ID: 16363929
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.. :(
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 16363942
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
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question