Forum Discussion
Set ws = Sys.OleObject("WScript.Shell")
ws.Run("c:\somefile.vbs")
how would I code the call in jscript?
- HKosova10 years agoSmartBear Alumni (Retired)
jloyzagawh wrote:
how would I code the call in jscript?
var oShell = Sys.OleObject("WScript.Shell"); oShell.Run("C:\\MyFolder\\MyScript.vbs");
- FlossyThePig8 years agoOccasional Contributor
Sorry to resurrect this topic but I am moving from QTP to TestComplete and have a lot of function libraries used in our existing framework. I have tried a simple exercise to try calling a function from a .vbs file but TestComplete fails to see the function. The function works when it is included in the TC script. I feel I've missed something obvious, but what?
Local script:
sub Main()
dim strDay, strWeek
Set ws = Sys.OleObject("WScript.Shell")
ws.Run("C:\string_functions.vbs")
strWeek = "Sun,Mon,Tues,Wed,Thus,Fri,Sat"
'local function
strDay = ChooseStr(strWeek, 3 )
Log.Message ("Day using function ChooseStr = " + strDay)
'external function
strDay = StrChoose(strWeek, 3)
Log.Message ("Day using external function StrChoose = " + strDay)
end sub
Function ChooseStr(ByVal sCSV, ByVal nIndex)
Dim values
values = Split(sCSV,",")
ChooseStr = values(nIndex)
End Function
External file ("C:\string_functions.vbs")
Option Explicit
Function StrChoose(ByVal sCSV, ByVal nIndex)
Dim values
values = Split( sCSV,",")
StrChoose = values(nIndex)
End Function- HKosova8 years agoSmartBear Alumni (Retired)
Hi Flossy,
Add your .vbs file as an existing item to your project. Then in your main script, use:
'USEUNIT string_functions
sub Main()
...
strDay = ChooseStr(strWeek, 3)
' or prefix the function name with the file name
strDay = string_functions.ChooseStr(strWeek, 3)
...
end subThat said, this specific example (reading an item from a comma-separated list) can be replaced with TestComplete's built-in function aqString.GetListItem:
strWeek = "Sun,Mon,Tues,Wed,Thus,Fri,Sat"
aqString.ListSeparator = "," strDay = aqString.GetListItem(strWeek, 2) ' Indexes start from 0, so the 3rd item has index 2
Related Content
- 13 years ago
- 8 years ago
Recent Discussions
- 5 hours ago
- 6 hours ago