How to calculate a formula in an array(index)

jerry

New member
Joined
Mar 28, 2005
Messages
1
Programming Experience
Beginner
Thanks in advance for the help.

Am working with parallel arrays. There are math formulas stored in Formula(index) that do calcs on Value1(index) and Value2(index) and then store the result in Answer(index).

Two things usually happen: crash or the formula itself is displayed without evaluation.

I tried several different approaches but here is the current subroutine:

Sub...
Dim index As Integer
Dim L, Q, D As Double
For index = 0 To upperBound
Q = CDbl(Value1(index))
L = CDbl(Value2(index))
'D = (L / 60 * 3) * Q ' Test L & Q in a calc.
D = CDbl(Formula(index)) 'Value2(index)
Answer(index) = CStr(D)
lstDisplay.Items.Add("CalcSub= " & Answer(index)) 'Test Answer
Next
End Sub

How do I force Formula(index) to calculate?
 
What exactly are you storing in Formula(index)? If these are mathematical formulas of some kind, you'll need to build a mini parser and evaluator (which is hard work!). If the formulas are known at compile-time, then there is another solution...
 
Back
Top