Question

I am working on a project to re-write something i have created in the past. Basically its an HTA with button choices for Application installs. Currently it is very long and repetitive so I am trying to clean it up a bit.

I have the following code which works if I set FilePath to a Function value (FilePath = ApplicationOne() ). I need FilePath to be able to be set based off of the button choice.

I basically need a file location assigned to FilePath based off of a button click. It can be set up differently than below but it does need to be separated because the Application Install has a lot more to it then shown below. Doing this will create a much cleaner design and will make future updates much easier.

Any thoughts on how to accomplish this?

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
Was it helpful?

Solution

You could define a global variable (outside of any function in your HTA) that contains the active application path. Your button click events can just update the value of this variable and your ApplicationInstall() sub can just read it. It would essentially act as a property of your module.

<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top