0
votes

I am learner to vbscripting and as a beginner trying to execute the below code. But I keep getting the compilation error [Please see error message below]. I am not sure as I do not see any error in the code. Also, I made sure that I type in all the text instead of copy-paste from web. Please do suggest.

Below is the code

<html>
<body>
<script language = "vbscript" type = "text/vbscript">
<document.write("Hello World!")
</script>
</body>
</html>

Error Message:

Script: C:\VB Script- Learning\Programmes\1.vbs
Line: 1
Char: 1
Error: Expected Statement
Code: 800A0400
Source: Microsoft VBScript compilation error

Thanks!

2
VBScript is not VB.NET - Ňɏssa Pøngjǣrdenlarp
try document.write("Hello World!") instead of <document.write("Hello World!") - TEK
Thanks for correcting the code - Abhishek Dingre

2 Answers

1
votes

The content of your file is HTML with a VBScript script block, but you're apparently trying to run it as a standalone VBScript (.vbs). That won't work. Either save the file as .htm and open it with Internet Explorer (make sure to add a header <meta http-equiv="x-ua-compatible" content="IE=9"> if you have Internet Explorer 11):

<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=9">
</head>

<body>
<script language="VBScript" type="text/vbscript">
document.write "Hello World!"
</script>
</body>
</html>

or remove all HTML and replace document.write with WScript.Echo if you want to run it as a .vbs file with wscript.exe or cscript.exe:

WScript.Echo "Hello World!"
1
votes

Remove the "<" (and the ()) from

<document.write("Hello World!")

to get

document.write "Hello World!"