我正在研究一个项目来重写我过去创造的东西。基本上它是一个带有按钮选项的HTA,用于安装应用程序。目前它很长很重复,所以我想稍微清理一下。
如果我将FilePath设置为Function值(FilePath = ApplicationOne()),我有以下代码。我需要FilePath才能根据按钮选择进行设置。
我基本上需要一个基于按钮点击分配给FilePath的文件位置。它可以设置为与下面不同,但它确实需要分开,因为应用程序安装还有很多其他内容,如下所示。这样做可以创建更清洁的设计,并使未来的更新变得更加容易。
有关如何实现这一目标的任何想法?
Sub ApplicationInstall
Dim FilePath
Set WshShell = CreateObject("WScript.Shell")
FilePath = "SomethingHere" '<---- Change This
WshShell.Run FilePath, 1, true
End Sub
Function ApplicationOne()
strPath = "\\This\is\a\file.cmd"
ApplicationOne = strPath
End Function
Function ApplicationTwo()
strPath = "\\This\is\a\file.cmd"
ApplicationTwo = strPath
End Function
Function ApplicationThree()
strPath = "\\This\is\a\file.cmd"
ApplicationThree = strPath
End Function
答案 0 :(得分:0)
您可以定义包含活动应用程序路径的全局变量(在HTA中的任何函数之外)。您的按钮单击事件只能更新此变量的值,您的ApplicationInstall()子只能读取它。它本质上可以作为您模块的属性。
<script language="vbscript">
Dim m_strPath ' Page/Module-level variable
Sub cmdButton1_Click()
m_strPath = <application path 1>
End Sub
Sub cmdButton2_Click()
m_strPath = <application path 2>
End Sub
Sub ApplicationInstall()
If Len(m_strPath) > 0 Then
CreateObject("WScript.Shell").Run Chr(34) & m_strPath & Chr(34), 1, True
End If
End Sub
</script>