calculate equation stored in string

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Phil (pcgerlach_at_ati-ae.com)
Date: 08/24/04


Date: Tue, 24 Aug 2004 08:03:32 -0700

I'm an amateur and working on a module that uses values
entered by a user in form to fill in variables in an
equation. Its then solved and the answer output to the
form. The equation changes though based on the user's
selection in a listbox and is stored as a string
variable "E".

The problem I'm having is in the calculation. I can't seem
to get the user input variables to fill in the equation.
Both the equation string and the user's variables have the
same "L" and "W" designation. I thought this would
automatically fill-in-the-blank on the equations. When
that failed, I tried to pass the equation to the EVAL
function, but also failed. The one clue I have is that I
can enter the equation exactly as stored in the table
extracted from and it solves it wonderfully. What am I
missing? My code is shown below. Thanks in advance for
your help.

'on error resume next
    
Dim L As Single
Dim W As Single
Dim A As Single
Dim E As String
         
L = Forms!fCalc.tbxLen.Value 'store user specified
length in L
W = Forms!fCalc.tbxWid.Value 'store user specified
girth in W
    
'Find the equation to use based on users selection in list
box and store in E
E = DLookup("Equation", "tOptions", "Forms!
fCalc.lbxOptions = [OptionsID]")
    
'Fill in user variables and calculate equation
A = Eval(E)
    
'Output result to form
Forms!fCalc.lblAMain.Caption = A
Forms!fCalc.lblAShdw.Caption = A
    



Relevant Pages

  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Help answer these 70-310 questions
    ... One argument is the string ... Dim output As New StringBuilder ... EmployeeLocations. ... You create a strongly named serviced component. ...
    (microsoft.public.cert.exam.mcsd)