18
Thu, Apr
5 New Articles

Microsoft Computing: Windows Scripting, Part II

Microsoft
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Last month, I began an examination of coding for Windows using VBScript (see "Windows Scripting, Part I"). I used VBScript to illustrate the convenience of building a small instruction set to run in a Windows batch environment. This month, I'll move on to the more usual application of scripting: as a Web browser application. In such an application, the container for the user interface is not a standalone Windows application. The base program the user runs is a Web browser, and the "program" is a set of source code statements that are embedded within the current page's HTML. The browser interprets the instructions and creates the user interface inside the browser's display area. All the tedious details of laying out the components of the interface are handled by IE.

When to Use VBScript in a Browser

As an IT professional, you may well wonder if VBScript is something you should be interested in. Of course, the answer is "it depends." These are some of the factors to consider when evaluating a VBScript solution:

  • Is the application at hand for internal use only, where all of the conditions are known? Note that VBScript is natively supported in Internet Explorer only; other browsers may not run your script.
  • Is the application going to involve the participation of a Web server? If the processing is local to the client, VBScript may be a good fit. If the application includes processing provided by a server, you should probably consider an ASP or ASP.NET solution. (See MC Press Online articles on Active Server Pages and ASP.NET.) Several non-Microsoft languages are available as well.
  • Is there a reason the application may not be installed on the PC? For example, a user may not have authority to install software, but Internet Explorer is already installed. If the application can be written in VBScript, the user can access it without the need for a regular installation to have taken place. Further, it can be very convenient to be able to use any nearby PC with an Internet connection, rather than one's own all the time.
  • Is the application small and relatively simple? Remember, the scripting code will be embedded within an HTML page, mixed among the instructions for displaying images, the links to other pages, and the like.

JavaScript vs. VBScript

JavaScript and VBScript are the most popular scripting languages for Web browser applications. The advantages and disadvantages of each are pretty clear:

  • VBScript is a subset of Visual Basic (VB), so is easy to pick up if you've programmed even a little in VB. On the downside, VBScript is not supported on all browsers. Further, VBScript has been used to exploit exposures in browser security.
  • JavaScript is supported on almost all browsers, but if you don't know Java, learning JavaScript can be challenging.

Ironically, when you use Visual Studio (VS) to create an ASP application, VS generates JavaScript as part of the client code. That's because ASP is supported on most servers, many of which are part of non-Microsoft environments, and JavaScript will likely be supported on all of the clients.

VBScript is a purely Microsoft technology and is natively supported in Internet Explorer. It is not natively supported in other browsers. This may not be a problem for internal environments where the choice of browsers is standardized and you know IE will be used. For public applications, where the browser is an unknown, VBScript may not be acceptable. If your application is going to run on various browsers, you should probably use JavaScript because it's a more universally supported scripting language.

VBScript can be used to do most of the things that VB can do; the principle difference is that VBScript does not have its own container and process, and VB does. With some limitations, VBScript can do many of the things that VB can: call a function or procedure, compare and branch, iterate through arrays, create objects, etc. Plus, VBScript can be enhanced with Web content.

A VBScript Web Example

To illustrate what VBScript code looks like, consider a typical role for VBScript running in a browser: validating user input (Figure 1).

http://www.mcpressonline.com/articles/images/2002/Microsoft-VBScript2V4--09260500.png

Figure 1: Validating user input is a common use for VBScript.

The intelligence for a modest task like that can be executed locally at the client as VBScript. For example, required fields can be checked to see that they have something in them, fields intended to accept only numbers can be checked for numeric values, and email addresses can be checked for reasonableness. The following HTML contains embedded VBScript statements to illustrate the general approach.








' (D)

 CLASSID="CLSID:978C9E23-D4B0-11CE-Bf2D-00AA003f40D0"> ' (E)
    
    

*

 CLASSID="CLSID:8BD21D10-EC42-11CE-9E0D-00AA006002f3">
    



 CLASSID="CLSID:978C9E23-D4B0-11CE-Bf2D-00AA003f40D0">
    

*

 CLASSID="CLSID:8BD21D10-EC42-11CE-9E0D-00AA006002f3">
    



 CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57">
    


* - Required field



 CLASSID="CLSID:978C9E23-D4B0-11CE-Bf2D-00AA003f40D0">
    



VBScript in an HTML document will take the form of either the code that describes the components of the application (text boxes, buttons, etc.) or the functions and procedures that execute in reaction to an event (user input, a mouse button click, etc.).

The code to describe components is placed between

and
HTML statements (at D in the listing). The form description is part of the part of the document. To make sure that the procedures or functions that may be called are available, function and procedure definitions are usually coded into the section of the HTML document. These statements will be bounded by .

In the example listed, there is only one procedure: cmdOK_Click (statement B). This code will be executed when the user clicks the button. If the "Last name:" textbox is blank or if the email value is invalid, a message box is displayed (C).

In the

section, each component is described between and statements. You may include specifications for color, size, font, etc. for the component. You can't, however, specify where the components are to be placed within the form. You may only tell IE in what order the objects are to be laid out. Recall that IE is doing all of the object management. If the browser client area is small, the components will lay out differently than if there's more space.

Notice at statement A, VBScript lets me define ordinary VB-style variables (lName and eMail) with the Dim statement. These are global variables that may be accessed from any procedure or function.

Notice also the class ID statement contained in each of the sections (as at statement E). This is how Internet Explorer knows what kind of components to put in the form. The ID value is found in the executing PC's system registry and the appropriate component for that PC, and that version of IE is loaded into the form. The easiest way to find the component's class ID is to start an HTML document in Word and then select View/Toolbars and place a check next to the Control Toolbox entry. This will show the types of components that can be placed in the browser--labels, text boxes, combo boxes, command buttons, and so on. You can then select a component and draw it on your form. Word will generate the appropriate source code for the component and place it in an section of the page.

More VBScript Examples

Many good sources for example VBScript code are available. Two of the better resources are MSDN's scripting site and the W3School examples. Both of the common applications for VBScript are covered at the MSDN site.

If your application is more complicated or if the services of an intelligent Web server are required, you would do well to look into the more-capable ASP or ASP.NET approaches to browser-based solutions. But even so, HTML is used that is rooted on scripting basics. A familiarity with the scripting mechanisms employed will assist your understanding of the process.

Chris Peters has 26 years of experience in the IBM midrange and PC platforms. Chris is president of Evergreen Interactive Systems, a software development firm and creators of the iSeries Report Downloader. Chris is the author of The OS/400 and Microsoft Office 2000 Integration Handbook, The AS/400 TCP/IP Handbook, AS/400 Client/Server Programming with Visual Basic, and Peer Networking on the AS/400 (MC Press). He is also a nationally recognized seminar instructor. Chris can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it..

Chris Peters has 32 years of experience with IBM midrange and PC platforms. Chris is president of Evergreen Interactive Systems, a software development firm and creators of the iSeries Report Downloader. Chris is the author of i5/OS and Microsoft Office Integration Handbook, AS/400 TCP/IP Handbook, AS/400 Client/Server Programming with Visual Basic, and Peer Networking on the AS/400. He is also a nationally recognized seminar instructor and a lecturer in the Computer Science department at Eastern Washington University. Chris can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Chris Peters available now on the MC Press Bookstore.

i5/OS and Microsoft Office Integration Handbook i5/OS and Microsoft Office Integration Handbook
Harness the power of Office while exploiting the i5/iSeries database.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: