Results 1 to 3 of 3

Thread: Solve equation from textbox [VB6]

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2022
    Not where I'm supposed to be

    Solve equation from textbox [VB6]

    Hello all, I am trying to write a graphing program where the color of a pixel in rgb depends on the position of it. (ex: red value = y*x)

    The problem is that the equations for the red, green, and blue values will be controlled by the user from a textbox. I do not know how to go about converting the text of the text box into a formula to apply to x and y.

    All help appreciated! Thanks!

  2. #2
    Fanatic Member
    Join Date
    Jun 2015

    Re: Solve equation from textbox [VB6]

    I would probably use the ms script control and give the user access to your graphing class. User could write functions of defined prototype which you call as you process.

    You could include example functions they tweak and they can get as complex as they want with logic.

    Olaf has a pretty small and capable equation calculator on the forums here

    Anything more complex go with script control

  3. #3
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Sofia, Bulgaria

    Re: Solve equation from textbox [VB6]

    This is a sample how to evaluate complex formulas with JScript9 engine using built-in Active Scripting as provided by Windows.

    The idea is that with TixyScript.bas no dependency on Scripting Control is needed/used to evaluate custom JS expressions like this

    '--- Form1.frm
    Option Explicit
    Private m_uScript As UcsActiveScriptData
    Private Sub Form_Load()
        If Not ActiveScriptInit(m_uScript, "JScript9", Me) Then
            If Not ActiveScriptInit(m_uScript, "JScript", Me) Then
                ActiveScriptTerminate m_uScript
                Exit Sub
            End If
        End If
        '--- here you can add some custom functions or constants
        ActiveScriptRunCode m_uScript, "function hypot(x, y) { return Math.sqrt(x*x + y*y) }"
    End Sub
    Private Sub Form_Click()
        Dim vResult As Variant
        '--- first declare a function with two parameters which can evaluate your expression
        ActiveScriptRunCode m_uScript, "function myfunc(x, y) { return (" & Text1.Text & "); }"
        '--- then call this function by passing values for actual arguments
        vResult = ActiveScriptCallFunction(m_uScript, "myfunc", 5, 10)
        '--- show the result
        MsgBox "vResult=" & vResult, vbExclamation
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        If Cancel = 0 Then
            ActiveScriptTerminate m_uScript
        End If
    End Sub
    The sample can evaluate an expression like x*y placed in Text1 textbox on the Form1 form.


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