r/vbscript•
JGN1722

Using vbscript along with html

Hello everyone ! I need help because I can't figure out how to put vbscript code into an html page.

What I'd like to do is a page with a button on it, and when this button is clicked, it activates a script that either modifies the inner html of the current page, or creates another html page on which I can write what I want.

I've tried to do the second option by writing a code that creates a new instance of the internetexplorer.application object, and then writes something in it's html, but sadly it doesn't work

Could someone help me, or send the link to a website that explains how to do that ? I have no experience of using vbscript along with html

Posted Jun 30, 2022, 2:16 PM UTC

510
hackoofr•

You should use Vbscript with HTA (HTML Application)

Another thing can you give us more information about your Vbscript code, just post it

3
JGN1722OP•

What I want to do is a basic text editing program, in which you can write, read and store text "files" (I do it as a challenge, I know vbscript is not the easiest way to do it), so my code is more than a hundred lines long, and I'm afraid if I send just a sample of it it won't be understandable.

And, since I use a internet explorer page as an UI and I want to trigger the action when I click a button on the page, I'm not sure an hta file is the suited solution. Maybe I should use javascript instead of vbscript to do it ?

1
jcunews1•

Use HTA as suggested, instead of HTML. HTML will be forced to be opened with a web browser which doesn't have any or have very limited access to local system resources. e.g. scripts run in web browsers do not have access to local file system.

HTA support both JavaScript and VBScript. Either one or both can be used.

1
JGN1722OP•

Yes, finally I think I'm going to do that, I just found out about the capabilities of the HTAs and I want to learn how to use them, they allow to do things that are completely incredible compared to what vbs alone can do

1
hackoofr•

Here is an example for editing text files with HTA-Vbscript: Mini-Notepad.hta

 <html>
 <HEAD> 
 <TITLE>Application : Mini-Notepad</TITLE>
 <HTA:APPLICATION ID = 'Mini-Notepad'
 BORDER="THIN"
 BORDERSTYLE="NORMAL"
 CAPTION = "Yes"
 CONTEXTMENU = "Yes"
 ICON = "Notepad.exe"
 INNERBORDER="NO"
 SHOWINTASKBAR = "Yes"
 SINGLEINSTANCE = "Yes"
 SYSMENU = "Yes"
 />
 <script language="VBScript">
 ' -----------------------------------------------------------------------------------------
 ' Sub called on change selection of file name to process.
 Sub FileChoice() 
 	Const ForReading = 1, ForWriting = 2 
 	Dim oFso, f
 	Dim stFile
 	stFile = inFile.value
 	Set oFso = CreateObject("Scripting.FileSystemObject")
 	if oFSO.FileExists(stFile) then
 		Set f = oFso.OpenTextFile(stFile, ForReading)
 		txtFile.value = f.ReadALL
 		f.Close
 	else
 		msgbox "File " & vbCrlf & stFile & vbCrlf & "Inaccessible !",vbCritical,"interface-hta"
 	end if
 	set f = Nothing
 	set oFso = Nothing
 end sub
 ' -----------------------------------------------------------------------------------------
 ' Save text file
 ' -----------------------------------------------------------------------------------------
 Sub btSave_OnClick()
 	Const ForReading = 1, ForWriting = 2 
 	Dim oFso, f
 	Dim stFile
 	stFile = inFile.value
 	if stFile ="" then
 		Msgbox "First ! You must select a file to process !",48,"First ! You must select a file to process !"
 		exit sub
 	end if
 	Set oFso = CreateObject("Scripting.FileSystemObject")
 	Set f = oFso.OpenTextFile(stFile, ForWriting)
 	f.write txtFile.value
 	f.close
 	MsgBox "The file " & chr(34) & inFile.value & chr(34) &" was successfully saved !",64,"File Saved !" 
 	set f = Nothing
 	set oFso = Nothing
 end sub
 ' -----------------------------------------------------------------------------------------
 </script>
 </HEAD>
 <BODY>
 <INPUT TYPE="file" NAME="inFile" SIZE="60" onChange="FileChoice">
 <input type="button" value="Save" name="btSave" >
 <BR>
 <TEXTAREA NAME="txtFile" ROWS="40" COLS="100" >
 </TEXTAREA>
 </BODY>
 </html>
2
JGN1722OP•

That's just... Impressive

Congratulations

I'm still going to continue my project, though, because I have a friend to prove wrong, he said vbscript was useless

2
hackoofr•

You can show him those tools in HTA :

1
JGN1722OP•

I'll make sure he sees them, thank you :)

1
hackoofr•

You can show him those tools in HTA too :

1
hackoofr•

You can also take a look at this example : You can learn from it many tricks and tips

2
JGN1722OP•

thank you very much ^^

2