Results 1 to 2 of 2

Thread: Ad Hoc Formulas

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Location
    Houston
    Posts
    9
    I've got a design dilema. I need to add the capabilites to a web site to allow the users to input metric conversion formulas into SQL server, extract the formulas from the database and use them with values passed to an ASP page. The problem I'm having is I don't know how to get either SQL Server or the ASP page (vbscript) to use the formula extracted from the database as a mathematical function.

    If there is a solution in Visual Basic, I can easily add an ActiveX control to the web page to get the desired result.

    There probably is no alternative to parsing the string of characters extracted from the database, but if someone does know how to get either SQL Server, VBScript or Visual Basic to recognize the string as mathematical operators that would be ideal. Of course, if anyone has a formula parser, that would work too.

    Many thanks for any help

  2. #2
    New Member
    Join Date
    Feb 2001
    Posts
    11
    From MS Tips of the Week http://msdn.microsoft.com/vbasic/tec...ps.asp#3-20-00

    For the week of March 20th, 2000
    Evaluate string formulas in Visual Basic

    If you've come to Visual Basic from Microsoft Access, you probably miss the handy Eval() method. This method evaluates a supplied string as though it were code. As a result, you could easily evaluate mathematical expressions passed as a string, like so:

    iResult = Eval("(2 * 3) + 5)")

    which fills iResult with the value 11.
    To achieve this same functionality in Visual Basic, you've no doubt resorted to complicated string parsing functions. Or perhaps you added Access' DLL to your project, which may have seemed like an awful lot of DLL for such a simple method.Now, though, you'll be happy to know that you can use the Eval() method without a lot of overhead. Microsoft provides this functionality in its Script Control. This very lightweight ActiveX component is available so you can add end-user scripting ability to your applications. However, as a result, it also comes with an Eval method. Adding this component to your project provides very little overhead and gives you the ability to evaluate mathematical strings.To download this OCX, visit http://msdn.microsoft.com/scripting/. Select the Script Control link, then follow the Download instructions. The following code shows the simple Visual Basic we added to a command button's click event. The SC1 script control evaluates a mathematical formula in the txtFormula textbox.

    Private Sub Command1_Click()
    MsgBox txtFormula & " = " & SC1.Eval(txtFormula)
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width