class - .hta语法错误,创建类

标签 class vbscript hta

vbscript 在 .vbs 文件中工作正常。 当然,当我在 .vbs 文件中运行 vbscript 代码时,我取消注释 'msgbox 行。

当我加载以下文件时,我在第 42 行收到一条错误消息,没有任何附加说明。

如有任何建议,我们将不胜感激。

如果解决这个问题,我将创建一个菜单来调用 PDF 文件、.mp3 音频文件和 .mp4 视频文件

这是我迄今为止创建的代码:

<html>
<head>
<title>My HTML application</title>
<HTA:APPLICATION
  APPLICATIONNAME="My HTML application"
  ID="MyHTMLapplication"
  VERSION="1.0"/>
</head>

<script language="VBScript">

Sub Window_OnLoad
  'This method will be called when the application loads
  'Add your code here
   ' copyright JSWARE
 'FileExt.vbs.
 '-- File extension default program Class.
 '-- send a file extension to Function and Get path of default program.

 Dim CE, txtExt, htmlExt, zipExt, pdfExt, mp4Ext
 Set CE = New ClsExt

  txtExt = CE.GetDefaultProgram("txt")
   'MsgBox "TXT" & vbcrlf & txtExt

  htmlExt = CE.GetDefaultProgram("html")
   'MsgBox "HTML" & vbcrlf & htmlExt

 htmlExt = CE.GetDefaultProgram("zip")
   'MsgBox "ZIP" & vbcrlf & htmlExt

 pdfExt = CE.GetDefaultProgram("pdf")
   'MsgBox "XYZ" & vbcrlf & pdfExt

 mp4Ext = CE.GetDefaultProgram("mp4")
   'MsgBox "mp4" & vbcrlf & mp4Ext

Set CE = Nothing

'_______________ START ClsExt Class ____________________________

Class ClsExt
Private SH, CK1, CK, s1, s2, sType

   Private Sub Class_Initialize()
      CK = "\Shell\Open\Command\"
      CK1 = "\Shell\Opennew\Command\"
      Set SH = CreateObject("WScript.Shell")
   End Sub

  Private Sub Class_Terminate()
     Set SH = Nothing
  End Sub

  Public Function GetDefaultProgram(sExt)
     If left(sExt, 1) <> "." Then
         sExt = "." & sExt
     End If
  On Error Resume Next
    Err.clear
         sType = SH.RegRead("HKCR\" & sExt & "\")     '--look up ext in HKCR to Get file type (ex.: "txtfile")
            If (Err.number <> 0) or (len(sType) = 0) Then
               GetDefaultProgram = ""
               Exit Function
            End If

        s1 = SH.RegRead("HKCR\" & sType & CK)   '--Shell\open\command or.....
           If (Err.number = 0) and (len(s1) <> 0) Then
                s2 = Stripit(s1)
                GetDefaultProgram = s2
                Exit Function
           End If
              Err.clear
             s1 = SH.RegRead("HKCR\" & sType & CK1)    '--shell\opennew\command.
                If (Err.number = 0) and (len(s1) <> 0) Then
                    s2 = Stripit(s1)
                   GetDefaultProgram = s2
                   Exit Function
               End If
         Err.clear
        s1 = SH.RegRead("HKCR\" & sExt & CK) 
            If (Err.number = 0) and (len(s1) <> 0)  Then
               s2 = Stripit(s1)
              GetDefaultProgram = s2
               Exit Function
           End If

      GetDefaultProgram = ""     '--If none of these checks have found anything return "".
 End Function     

Private Function Stripit(sp)    '--clean up default program string. 
   Dim ept, sf
     On Error Resume Next
  ept = instr(1, sp, "exe", 1)  '--find End of exe path.
     If ept <> 0 Then
         sf = left(sp, ept + 2)
     Else
       ept = instr(1, sp, "com", 1)
        If ept <> 0 Then
          sf = left(sp, ept + 2)
        End If
   End If
    If left(sf, 1) = chr(34) Then  '--take off any quotes or spaces.
       sf = right(sf, (len(sf) - 1))
    End If
   sf = trim(sf)  
   Stripit = sf
 End Function

End Class






    'Set wmp = CreateObject("WMPlayer.OCX")
    'wmp.openPlayer("E:\svr1\K\data\Steinberg Nisan\AV\2013-04-15_\VID_20130415_171550_FIXED_.mp4")
    'wmp.openPlayer(".\VID_20130415_191439_FIXED_.mp4")

End Sub

</script>

<body bgcolor="white">

<!--Add your controls here-->
<br /><br />
<font size="7">
<b><u>Table of Contents:  Index to Folder </b></u></font>
<br /><br />



<!--{{InsertControlsHere}}-Do not remove this line-->
</body>
</html>

最佳答案

您不能在子窗口中声明类,并且在 Sub Window_OnLoad 内有 Class ClsExt

关于class - .hta语法错误,创建类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21794454/

相关文章:

javascript - 如何以编程方式单击从另一个页面加载的按钮?

c++ - 为什么要使用 const 成员函数?

c++ - 类的链接列表,如何在遍历时调用toString?

javascript - 为什么有些方法在原型(prototype)中却不能通过 Object.assign 传递,而另一些方法却在原型(prototype)中

javascript - 了解 IFrame 内的网页(位于 HTA 中)何时完成加载

javascript - 将输出转换为 javascript 的批处理文件命令(net user 和 findstr)

java - 开始一个新项目,如何架构呢?

vbscript - 以编程方式测量打印作业时间

.net - 如何调试 "Wrong number of arguments or invalid property assignment"vbscript .NET 互操作

vbscript - 查找事件驱动器的命令