user7192474
user7192474

Reputation:

Two types of VBScript?

So recently, I had a friend teach me some VBScript. This is the following code.

help = MsgBox("Click on 'Yes'",vbYesNoCancel, "Orders")
WScript.Echo help

The file is called File.vbs and as far as I know .vbs stands for Visual Basic Script file. But recently, I've been searching on the internet and find VBS to be another thing. It looks like html or xml. Something like this.

<% Option Explicit
 %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
     "http://www.w3.org/TR/html4/loose.dtd">
 <html>
    <head>
        <title>VBScript Example</title>
    </head>
    <body>
        <div><% 
        ' Grab current time from Now() function.
                ' An '=' sign occurring after a context switch (<%) is shorthand 
                ' for a call to the Write() method of the Response object.
        Dim timeValue = Now %>
        The time, in 24-hour format, is 
                <%=Hour(timeValue)%>:<%=Minute(timeValue)%>:<%=Second(timeValue)%>.
        </div>
    </body>
 </html>

Can someone explain if I'm looking at the correct language or something? Thanks in advance!

Upvotes: 1

Views: 2281

Answers (1)

user692942
user692942

Reputation: 16671

There are not two types of VBScript, the difference is purely in the context of how it is used.

The VBScript Scripting Language cannot run standalone: it has a dependency on a Scripting Host which can take various forms depending on the context of its execution.

For client-side scenarios there are a few ways it can be used:

  1. Through the Windows Scripting Host which can execute .vbs and .wsf extension files (for more on WSF see Windows Script File).

  2. Through Internet Explorer (deprecated from Microsoft Edge onwards to bring it in line with Modern Standards Browsers) via the <script> HTML tag.

  3. Through an HTA which is similar to Internet Explorer but is less restrictive and designed to be used in controlled environments where access to local resources (which would otherwise be considered unsafe) is allowed. It's typically used for designing web-based interfaces to use within an Enterprise (the mshta.exe is included in most versions of Windows).

For server-side scenarios the options are more straightforward:

  • Classic ASP is a server-side script engine that incorporates VBScript as its default scripting language. Classic ASP runs as an ISAPI extension inside IIS and can be configured to process any Active Scripting Language (which to date includes VBScript and JScript, but there is also a custom implementation of Perl known as PerlScript that will run on a non-IIS based server).

    In the second example, the weird brackets around the VBScript <% and %> are part of the Classic ASP Script Engine. They are known as an "Inline Code Block": they help the Classic ASP Interpreter identify what code it needs to process before the final HTML is returned by the Web Server. It would be wrong to call Classic ASP VBScript, as it has its own object model which is completely independent of VBScript — it incorporates objects such as Request, Response and Server that can only be used in the context of Classic ASP.


Useful Links

Upvotes: 3

Related Questions