I am working on an equation grapher in visual basic 6, but I am encountering an error upon running my program. I have narrowed down the error to the below block of code.
Option Explicit
Private Sub cmdGraph_Click()
Dim script_control As MSScriptControlCtl.ScriptControl
Dim x As Single
Dim y1 As Single
Dim y2 As Single
' Make a script control.
Set script_control = New MSScriptControl.ScriptControl
script_control.Language = "VBScript"
' Define the function.
script_control.AddCode _
"Function TheFunction(X)" & vbCrLf & _
" TheFunction = " & txtExpression.Text & vbCrLf & _
"End Function"
' Graph the equation.
y1 = script_control.Eval("TheFunction(" & xmin & ")")
For x = xmin + Dx To xmax Step Dx
' Evaluate the next value.
y2 = script_control.Eval("TheFunction(" & x & ")")
' Draw the next line.
picGraph.Line (x - Dx, y1)-(x, y2)
' Save the current Y value.
y1 = y2
Next x
End Sub
I have checked the components:
- Microsoft windows common controls 6.0
- Microsoft windows common controls- 2 6.0
- Microsoft script control 1.0
so I don't think the problem lies within components.
The code highlighted is:
New MSScriptControl.ScriptControl
on line no. 10 of the code block I provided. Any help on what the problem could be would be appreciated, thanks.
Edit: I Changed the 4th line of the code block to:
Dim script_control As MSScriptControl.ScriptControl
opposed to:
Dim script_control As MSScriptControl.ScriptControl
The highlighted text is now the 4th line of the code block.