michaelekins
michaelekins

Reputation: 579

using VBScript in .hta file

I'm new to VBScripting but have been able to create some .wsf files utilizing VBScript which have helped me greatly.

I've decided to take this a step further and make them a little more interactive using HTML applications. I've done quite a bit of reading up on this and it looks like I can't use WScript in the .hta file, but I can't see a clean, simple way to get this to work. I'd really appreciate some pointers or best practice ideas to help get me on my feet with this.

Anyway, the code is this and hopefully is pretty self explanatory:

    set fs = WScript.CreateObject("Scripting.FileSystemObject")
    set oShell = CreateObject("Wscript.Shell")
    set objShell = CreateObject("Shell.Application")

    currDir = oShell.currentDirectory
    CreateFolder(C:\TEMP1234")


    Function CreateFolder(foldr)
        dim create
        if(fs.FolderExists(foldr)) then
            Msgbox "Folder already exists: "+foldr
        else
            fs.CreateFolder(foldr)
        end if
    End Function

</script>

<body>
<p>Please make selection</p>
<input type="checkbox" name="Selection" value="1.">Option 1<br>
<input type="checkbox" name="Selection" value="2.">Option 2<br>

<input id=runbutton class="button" type="button" value="OK" name="ok_button" onClick"getSelection">
&nbsp;&nbsp;&nbsp;
<input id=runbutton class="button" type="button" value="Cancel" name="cancel_button" onClick="CancelScript>

</body>

<script language="VBScript">

    Sub getSelection
        if Selection(0).Checked then
            option1
        end if
        if Selection(1).Checked then
            option2
        end if

        if radioChoice="" then
            exit sub
        end if
    end sub

    Sub CancelScript
        Self.Close()
    end sub

    sub option1
        Msgbox "Option 1 Selected"
    end sub

    sub option2
        Msgbox "Option 2 selected"
    end sub

</script>

Thanks in advance!

Upvotes: 1

Views: 5397

Answers (1)

Teemu
Teemu

Reputation: 23416

Some details from your code:

You've scripts allover the file. Put them in the head and / or body, but nowhere outside of these two elements.

WScript object is not available in HTA: fs = CreateObject("Scripting.FileSystemObject"); does the trick.

The quote here CreateFolder(C:\TEMP1234") is suspicious, it's either pairless or extra? Pathnames can't contain quotes, so there's something to fix.

There's a typo in the first input, missing = in <input ... onClick"getSelection">. This is critical, since getSelection is never called.

Upvotes: 1

Related Questions