One Function: Different Formulas for Different Inputs
I need to convert typing speeds in various units to other units. The input and output units can be any of:
- WPM = words per minute
- CPS = characters per second
- CPM = characters per minute
- SPW = seconds per word
etc.
Is there any way that I can define a set of expressions in strings with names that define the conversion to be done and then just execute the corresponding string?
For example, the expressions to convert between WPM & CPS are:
Code:
CPS = WPM * 5 / 60 = WPM / 12
WPM = CPS * 12
Can I define 2 constants:
Code:
Const WPM2XPS as String = "CPS = WPM / 12"
Const CPS2WPM as String = "WPM = CPS * 12'
and then if I am asked to do one of these, I just "execute" the appropriate string?
The only alternative that I know of is two Case statements -- one to check the input format and convert the data to some intermediate units and a second one to convert that to the output units.