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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Math Veriables Please Help. Just starting out 1

Status
Not open for further replies.

beck

Programmer
Mar 22, 1999
26
0
0
US
I have written a program that is math intensive. What I want to do is be able to run an interate to a sample situation. The sample would be something like this. Calculate the speed of a vehicle that left 30 feet of skid marks on a road that has a .7 to .85 friction factor. The initial calculation would be the Sqr(30*D*F) The D would be the distance the vehicle skidded and the F would be the friction factor. What I want to do is take the low friction factor of .7 and then in increments of .01 go up to .85 and display the results of that query in the selected series. I would also like to display the f value that was used for each speed result to the right of each result. That way the user could identify what f value was used for each particular speed calculation. It would be something like this. <br>
34.3 Mph .7 f<br>
34.6 Mph .71f<br>
35.0 Mph .72f<br>
Up to .85f Value which would be the maximum value. <br>
<br>
Any assistance would be greatly appreciated. Thank you in advance for your help. Please make the explaination easy as I am still learning. Thank you. <p> <br><a href=mailto:accrec@intergrafix.net>accrec@intergrafix.net</a><br><a href= > </a><br>
 
Hi beck<br>
<br>
Here is a simple little Sub to get you started<br>
<br>
Sub CalcSpeed(sngStart As Single, sngStop As Single, sngStep As Single, sngDistance As Single)<br>
Dim sngFricFact As Single<br>
<br>
Cls<br>
For sngFricFact = sngStart To sngStop Step sngStep<br>
Print Format$(Sqr(30 * sngFricFact * sngDistance), &quot;##0.0&quot;) & _<br>
&quot;MPH &lt;=&gt; &quot; & Format$(sngDistance, &quot;###&quot;) & _<br>
&quot;ft Distance & &quot; & Format$(sngFricFact, &quot;0.00&quot;) & &quot; Friction Factor&quot;<br>
Next<br>
End Sub<br>
<br>
You would call it as follows (for the numbers used in your example):<br>
<br>
CalcSpeed .7,.85,.01,30<br>
<br>
or you could pass numeric variables Dim'ed as Single to it, e.g.<br>
<br>
CalcSpeed FricStart!, FricEnd!, .01, Distance!<br>
<br>
You can improve on this Sub (and make it more usable) by storing the results in an array for later use or by turning it into a function which returns the result of a single calculation. This could then be called from a loop, etc.<br>
<br>
Hope this helps<br>
-Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top