Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear Screen (CLS) Using VBScript 1

Status
Not open for further replies.

DanaHallenbeck

IS-IT--Management
Sep 27, 2000
63
US
I am trying to replace an old batch file with a vbscript application running under cscript.exe in a DOS window. My problem is that I am using menus and need a way to clear the old menu so I can print the new one. I cannot get the DOS command "CLS" to work from within the script and have pretty much scoured the internet to no avail.

I tried various iterations of "WScript.Stdout.WriteLine cls" as well as a debug-type call I found on the internet. Nothing seems to clear the current DOS window and leave the cursor at the top of the window.

Thanks for any help.

Dana Hallenbeck
 
If you are converting the batches to VBScript, then maybe you should look at a more versatile interface than the command line. I would suggest creating an HTA. That would essentially allow you to use a truly graphical interface with a minimal amount of effort.

Failing that I don't know of a way to clear the command prompt. There are two other solutions that I can think of both of which are IMO inferior to using a HTA:

1) Use the execute command to open a command prompt. You will then have complete contol of it's STDOUT, STDIN, and STDERR and should be able to send it a CLS command.

2) Use the VBScript native MsgBox and InputBox commands to get user input and display user information and forgo the command prompt altogether.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
One other possiblility (also not the greatest) is to use the WriteBlankLines method on the WScript.StdOut object to move the menu that you no longer want visible off the screen or even out of the buffer.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks for the response.

An HTA interface would require extensive reprogramming since this batch file is quite complex...and I don't have a lot of HTML experience. I am looking for a quicker fix since this is needed soon.

I tried the WshShell.exec method, but it will not display a command prompt. You can run command line programs, but it does not display the window.

The inputbox would work, but is not quite as nice to look at. And I tried the WriteBlankLines method, but to get the menu centered on the screen I have to write more blank lines after the menu items. This leaves the cursor at the bottom of the screen and not at the prompt for information.

I do appreciate all the suggestions, and I will probably work on an HTA app over time to make this work better. In the meantime, though, I will probably keep the .bat file unless someone can find a way to clear the screen in a .vbs file.

Thanks again for the assistance.

Dana Hallenbeck
 
silly question: instead of cls, close the command window and open a new one for each menu???


if it is to be it's up to me
 
Here man all the code you need :)

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "CLS + {ENTER}"
Set WshShell = Nothing

Enjoy! :)
 
>Here man all the code you need...
Have you tried it yourself?
 
In theory that should work...In practice it doesn't. I tried that approach initially and it didn't work.

What I ended up doing was creating an HTA app. It took a while, but the interface is so much simpler now. I also created an XML file to hold the menu information, so all I needed to do was edit the XML file to add options and resulting values. Needless to say, I now have more HTML experience...

I appreciate everyones ideas, and thanks for the HTA suggestion TomThumbKP.

Dana
 
So any independent member voluntee to post back positive testing result if the script functions as cls in cmd/command.com? I like to know if rcraig's contribution is indeed working on certain windows os and I do not have the right os to test.
- tsuji
 
tsuji, craig's solution don't works for me: WinXP pro SP2, WSH 5.6
 
Depends on the command prompt:

cmd: does not work
command: does work
 
Thanks much for responding to my call, PHV and strongm. I do appreciate it.

Just to make the ground for mutual understanding, it works if we operate something like this at the console:
[tt]c:\>cscript //b //nologo cls_script.vbs[hard enter][/tt]
(with or without the //b //nologo, as it does not matter.) The end result should be that the prompt c:\>, for instance, would return back to the upper left of the screen. (If what accomplished is the prompt located at the lower left corner, we know we can do by writing enough blank line to the screen. And it is not what cls behaves.)

I can add that on command console it won't work for win9x/me. (I have much doubt on the universality of its working under command console on win2k+(?). I take strongm's word for granted and take note of this pending further investigation. xp seems excluded per PHV.) I'll leave this as a reasonable summing up for the moment.

Thanks again.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top