Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create averaging program

Status
Not open for further replies.

jcfrasco

IS-IT--Management
Apr 27, 2001
89
US
This is a utility program I would like to write to save a little time at work. What I want it to do is to take the weight of some parts from a database, lets say about 70 individual parts, select 29 of the values and average them. If the averaged value is not within a certain closeness of a user entered value then try again selecting a different group of 29 parts. Continue this until a value is found or until all parts have been checked and the value cannot be obtained.

I would appreciate any guidance in this little project.

Thanks!

jcfrasco
 
Not sure exactly what you're wanting guidance on. A good way to start any project though is to first write a flowchart, and then expand the boxes on your flowchart with some simple pseudo code if it's complex. This will usually make any design issues show up before you've wasted time coding.

With your 'select 29 items', I'm interpreting that to mean your program will select 29 random items. And that it is to select another 29 random items later on if your conditions aren't meant - and also to stop once all items have been checked.

The problem I see with that is that this will add up to an enormous amount of permutations and the coding would be quite significant to realise when every permutation has been checked.

Post back with some more information on exactly where you think you may run into trouble.
 
Just a thought, but could you not this as a query?

If you're using Access or SQL Server you can use the Top command:
(This query is off the top of my head and I can't test it as I use Sybase)

If this works (which I'm not sure it will), checks if the the avg weight is within 10% of the user's specified value.

select top 29 *, avg(weight) from myTable
where (avg(weight) >= UserValue * 0.9) and
(avg(weight) <= UserValue * 1.1)

If you can't use the Top command, remove it and then just loop thru the result set and take out the number of records you want.

lou

 
Sorry for not responding but I am not get the e-mails that there were responses to my question. Griffyn is correct that I would like to select 29 items and average them, if they do not meet the criteria then select another group of 29 untill all items have been checked or the criteria cannot be met.

Thanks!

jcfrasco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top