1. Home
  2. Computing & Technology
  3. Visual Basic
photo of Dan Mabbutt
Dan's Visual Basic Blog

By Dan Mabbutt, About.com Guide to Visual Basic since 2002

VBScript and Computer Administration

Sunday December 19, 2004

An About Visual Basic reader recently asked, "How do you clear screen using VBScript? Is it possible at all?"

First, the best answer I know to the question is, "Well ... it's possible but it's not easy. I couldn't find a prewritten solution either. As far as I know, VBScript doesn’t have any native ability to clear the screen. (If you know of a way, please let me know.)

The only way to clear the screen in a DOS console window using the WSH VBScript host that I could find would require the creation of an ActiveX object which calls several Win32 API functions. You could then call the this ActiveX OCX from your VBScript program. The basic method provided to this question by Microsoft (in a C++ program) is to use one API to get the size of the console window; calculate the number of characters in the window; and then write that many blank characters to the screen buffer using another API.

I haven't written this program for VBScript but it seems like it might be possible. Again, perhaps a kind reader could jump in and help out here.

Which indirectly brings up the reason why VBScript doesn’t support “clear screen”. The description above only applies to the WSH VBScript host. The reader didn't say if he was using WSH, IE, or IIS as the VBScript host. In each case, VBScript would have to do something completely different (I have no idea how this would work using the IIS host). That’s why this ability isn’t part of VBScript. VBScript isn’t a “stand alone” environment. It can only automate what the host supports. And in the case of “clear screen” what the host supports isn’t really defined.

The question caused me to review the information available at About Visual Basic for VBScript, however. And I wasn't happy with what I found. There were two articles and neither of them really covered the BIG uses of VBScript. So I'm doing something about that. This week, Part 1 of a completely revised version of VBScript - The System Administrator's Language has been added to the site. Part 1 covers where VBScript fits in and shows you a first example of how to use VBScript and one of the included VBScript objects to start managing Windows. Watch this space for Part II to be posted soon!

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.