根据按钮单击设置 VBscript 变量



我正在做一个项目,重写我过去创建的东西。基本上它是一个HTA,带有用于应用程序安装的按钮选择。目前它很长而且重复,所以我正在尝试清理一下。

我有以下代码,如果我将文件路径设置为函数值(文件路径 = 应用程序一()),则可以工作。我需要文件路径能够根据按钮选择进行设置。

我基本上需要根据按钮单击分配给 FilePath 的文件位置。它的设置方式可以与下面不同,但确实需要分开,因为应用程序安装具有更多内容,如下所示。这样做将创建一个更干净的设计,并使未来的更新更加容易。

关于如何实现这一目标的任何想法?

Sub ApplicationInstall  
    Dim FilePath    
    Set WshShell = CreateObject("WScript.Shell")
    FilePath = "SomethingHere" '<---- Change This
    WshShell.Run FilePath, 1, true
End Sub




Function ApplicationOne()
    strPath = "\Thisisafile.cmd"
    ApplicationOne = strPath
End Function
Function ApplicationTwo()
    strPath = "\Thisisafile.cmd"
    ApplicationTwo = strPath
End Function
Function ApplicationThree()
    strPath = "\Thisisafile.cmd"
    ApplicationThree = strPath
End Function

您可以定义一个包含活动应用程序路径的全局变量(在 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>

最新更新