将javascript转换为vbscript

时间:2014-08-31 09:08:28

标签: javascript vbscript

我尽可能地尝试将代码从javascript更改为vbscript ...如果在更改时出现任何错误,您能帮助我吗?

     <script  language='vbscript' type='text/vbscript'>

Dim myVar = "";

function auto(data) 
Dim path = '<%=session.getAttribute("PATH")%>' ;
   Dim DocId = '<%=session.getAttribute("REQDOCUMENTID")%>' ;
   Dim extension = '<%=session.getAttribute("FILEEXTN")%>' ;
   Dim userId = '<%=session.getAttribute("REQUSERID")%>' ;
   Dim apolloenv = '<%=session.getAttribute("REQAPOLLOENV")%>' ;

   if(extension != '') Then
          Dim ext = LCase(extension);
          Dim fso  = CreateObject("Scripting.FileSystemObject");
          if (fso.FolderExists(path)) Then                                   
                 path = path & DocId & "." & ext;
                 document.ViewONE.save(path);
                 myVar=window.setInterval(Call checkFile(path,ext),1000);      
          End If
          if(DocId <> 'null' AND apolloenv <> 'null' AND userId <> 'null') Then
                 getNote(DocId,apolloenv,userId,"autolaunch executed");
          End If   
   End If
 End Function

    function checkFile(path,ext)

   set fso  = CreateObject("Scripting.FileSystemObject");
   if(fso.FileExists(path)) Then
          Call openfile(ext, path);
          window.clearInterval(myVar);
End If
End Function




function openfile(ext, path) 
   if(ext == 'docx' || ext == 'doc'|| ext == 'docm') Then
          Dim oApplication = CreateObject("Word.Application");
          oApplication.Visible = true;
          oApplication.Documents.Open(path, false, 0);
   ElseIf (ext == 'xls'||ext == 'xlsx' ||ext == 'xlsm' ||ext == 'xlsb' ||ext == 'xltx' ||ext == 'xltm') Then
          Dim objExcel = CreateObject("Excel.Application");
          objExcel.Visible = true;
          objExcel.Workbooks.Open(path, false, 0); 
   ElseIf  (ext == 'pptx'|| ext == 'ppt' || ext == 'pptm') Then
          Dim objPPT = CreateObject("PowerPoint.Application");
          objPPT.Visible = true;
          objPPT.Presentations.Open(path, false, 0); 
   ElseIf (ext == 'msg' || ext == 'eml') Then
          WSH = CreateObject("WScript.Shell");
          WSH.run("file://"+path, 1);
   ElseIf (ext == 'jpg' || ext == 'tif' || ext == 'png' || ext == 'bmp' || ext == 'mdi' || ext == 'gif') Then
          imageWSH = CreateObject("WScript.Shell");
          imageWSH.run("file://"+path, 1);
   ElseIf (ext == 'txt') Then
          txtwshShell = CreateObject("WScript.Shell");
          txtwshShell.run("file://"+path, 1);
   ElseIf (ext == 'pdf') Then
          wshShell = CreateObject("WScript.Shell");
          wshShell.run("file://"+path, 1);
   Else
       msgbox "Please use the right click AutoLaunch option available in Apollo as this document type will not be supported by daejaviewer's AutoLaunch."
End If       
End Function

我不确定javascript中的getNote,Document,session.attribute函数是否将其更改为vbscript

1 个答案:

答案 0 :(得分:0)

在Javascript中,您可以在一个语句中声明和初始化变量:

var x = "whatever";

在VBScript中,你需要一个Dim和一个任务:

Dim x : x = "whatever"

在Javascript语句中以“;”结尾; VBScript不使用语句终止符 -

window.clearInterval(myVar);

应该抛出语法错误。附加示例:

oApplication.Documents.Open(path, false, 0);
==>
oApplication.Documents.Open path, false, 0

Javascript需要param list()到处都是;调用(Sub / Function / Method as a)Sub。

时,VBScript不使用param list()
window.clearInterval myVar

是上述电话的VBScript。

通过VBScript operators的文档来制作像

这样的行
if(ext == 'docx' || ext == 'doc'|| ext == 'docm') Then

体面。

字符串文字分隔符是“在VBScript中,而不是在Javascript中”(或“)。要检查Null(而不是字符串文字“null”),您需要IsNull()函数。所以

DocId <> 'null'

是一个双重错误。

在将对象分配给变量时,VBScript需要Set

Dim oApplication = CreateObject("Word.Application");
==>
Dim oApplication : Set oApplication = CreateObject("Word.Application")

可能会有更多错误;我建议您纠正指出的问题,并发布更好的修订版以获得有关剩余错误的帮助。