Option Explicit
Public a As Integer
Private Sub cmd_Click()
SC.Reset
SC.AddObject "MainForm", Me, True
On Error GoTo ErrorHandler
SC.AddCode "sub M" & vbNewLine & "dim nA" & vbNewLine & _
"nA=" & "2+(2*2)" & vbNewLine & "MainForm.a=nA" & vbNewLine & "end sub"
SC.Run "M"
Print Me.a
Exit Sub
ErrorHandler:
MsgBox Err.Number & vbNewLine + Err.Description, vbCritical, "Ошибка"
End Sub
Function myEval(s As String, Optional bError As Boolean, Optional sErr As String) As Double
Dim sc As New ScriptControl
On Error GoTo er
bError = True
sc.Language = "VBScript"
myEval = sc.Eval(Replace(s, ",", "."))
bError = False
er:
sErr = Err.Description
End Function
Function myRunScript(sFormula, Optional bError As Boolean, Optional sErr As String) As Variant
Dim sc As New ScriptControl
On Error GoTo er
bError = True
sc.Language = "VBScript"
sc.AddCode "Function myScript" & vbLf & "myScript = " & Replace(sFormula, ",", ".") & "End Function"
myRunScript = sc.Run("myScript")
bError = False
GoTo ok
er:
If sc.Error.Number <> 0 Then
If sc.Error.Number = 6 Then
bError = False
Else
sErr = sc.Error.Description & " в строке:" & vbLf & sc.Error.Text
End If
Else
sErr = Err.Description
End If
ok:
Err.Clear
End Function
function a()
{
var b=(2>3)?100:10;
return b;
}
Function IIF(Condition, TrueValue, FalseValue)
If Condition Then
IIF = TrueValue
Else
IIF = FalseValue
End IF
End Function
Сейчас этот форум просматривают: Google-бот, SemrushBot, Yandex-бот и гости: 10