1

I want to put my subroutines in an external file. When I press the help button it pops up errors. Even at startup it shows errors. If I put the contents of scripts.vbs within the HTA they work fine.

Here is the code:

Contents of scripts.vbs file:

Sub Window_Onload
  Msgbox "welcome"
end sub

Sub Help
  MsgBox "This is an example of progressbar in HTA written by Fredledingue.",,MyTitle
End Sub

Contents of HTA file:

<script type="text/vbscript" src="scripts.vbs">
</script>

<body bgcolor="GreenYellow">
<input id="BtnHelp" type="button" value="Help" onclick="Help">
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
htmler
  • 380
  • 1
  • 4
  • 12

1 Answers1

1

Importing the script file like that should work, as long as the HTA and VBScript files are located in the same folder. You need to make sure that the <script> tag is closed though:

<script type="text/vbscript" src="scripts.vbs"></script>

If you still get errors you need to show them (full error message, including error number and the line raising the error).

With that said, I'd recommend against externalizing code from HTAs, because it reduces mobility. A self-contained HTA can easily be copied to wherever you like. The need to keep several files together has a negative impact on that.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Error-onclick'help btn':object doesn't support property or method and the char 1 of line – htmler Jul 19 '15 at 12:45
  • 2
    @HarmeetSinghBrar It's not possible that you got this error from the code you posted. Please [edit your question](http://stackoverflow.com/posts/31499095/edit) and show your actual code as well as the *exact* error message. – Ansgar Wiechers Jul 19 '15 at 13:54
  • Oh.thanks I Retype My Whole Code now its working clean and fast ...can i use more than one scripts file?? – htmler Jul 19 '15 at 15:45
  • @HarmeetSinghBrar Yes. You can also mix sourced files and embedded script sections. – Ansgar Wiechers Jul 19 '15 at 15:48