Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Option Explicit and MSScriptControl.ScriptControl

I allow my users to write VBScript and I execute it using MSScriptControl.ScriptControl. I just finished a routine that will parse all script written without having to run anything, it works fine except for stray text that the control is not raising an error for. What I would like to do is use 'Option Explicit' but I am not sure where to do this at in the control. Below is my current code.

Thanks for any assistance.

Dan

On Error Resume Next

Err.Clear

Script.Error.Clear
Script.Reset
Script.Modules.Add "Main"
Script.Modules.Item("Main").AddCode sErrorTestScript

If Err.Number <> 0 Then
MsgBox "Error in script. " & vbCrLf & vbCrLf & _
"Description - " & Script.Error.Description & vbCrLf & _
"Number - " & Script.Error.Number & vbCrLf & _
"Line - " & Script.Error.Line + lErrorTestIndex - 1 & vbCrLf & _
"Source - " & cErrorTestScript.Item(lErrorTestIndex)(0), vbInformation, AppTitle

bResult = False

End If
[1074 byte] By [danielreber] at [2007-11-11 10:13:18]
# 1 Re: Option Explicit and MSScriptControl.ScriptControl
Wouldn't it be as simple as determining if the script they wrote has the phrase "Option Explicit" or not and if not, simply prefix it to the string. This is not perfect but should give you the idea:

If InStr("Option Explicit",sErrorTestScript) = 0 Then
Script.Modules.Item("Main").AddCode "Option Explicit" & vbCrLf & sErrorTestScript
Else
Script.Modules.Item("Main").AddCode sErrorTestScript
End If
cody3 at 2007-11-11 17:23:01 >