PDA

View Full Version : Can Jscript and VBScript co-exist


BrandonG
08-16-2007, 04:19 PM
I have a fairly large build script. The default language is VBS and everything is written in VBS. I have a need to utilize functionality that is in js and not vbs. Is there a way to make them co-exist? The location where I need it is inside of a step that has a TON of vbs that i wouldn't want to rewrite.

kinook
08-16-2007, 05:00 PM
Other than Run Script steps, all other step script code (script events, script expressions, etc.) must use the default script language (http://www.visualbuild.com/Manual/miscopt.htm). You might be able to get away with dynamically changing (http://www.visualbuild.com/Manual/defaultscriptengineproperty.htm) the default script language mid-build.

BrandonG
08-17-2007, 10:14 AM
Is there a way to call another step from within a step? Or maybe a custom action? We could always embed the js inside of another step or action.

kevina
08-17-2007, 02:51 PM
Below is a sample Run Script vbscript that creates a new project with a single Run Script (jscript) step, which retrieves the computer name with jscript, which the VBScript "uses". This is derived from the Script.bld sample.


jscript = "var cname = new ActiveXObject('WScript.Network').ComputerName;" & vbcrlf & _
"Application.Macros(vbldMacroProject).Add('CNAME', cname);"

val = RunJScript(jscript, "CNAME")
msgbox val

Function RunJScript(script, macroName)
Dim objApp, objBld, objStep

' create VisBuildPro app and build objects and connect
Set objBld = CreateObject("VisBuildSvr6.Builder")
Set objApp = CreateObject("VisBuildSvr6.Application")
objBld.Initialize objApp

' create an empty LOGFILE macro to disable logging of the
' temporary project
objApp.Project.Macros.Add "LOGFILE", ""

' create a project that creates a file
' add a write File step and set its properties
Set objStep = objApp.Project.Steps(vbldStepMain).Add("Run Script")
objStep.Name = "Run JScript"
objStep.Indent = 0
objStep.Property("Language") = "JScript"
objStep.Property("Script") = script

' build the dynamic project
if objBld.SyncBuild() = vbldBuildCompDone Then
RunJScript = objApp.Project.Macros(macroName).Value
Else
builder.LogMessage "Error in script"
step.BuildStatus = vbdStepStatFailed
End If
End Function