Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Clear Screen

1,016 views
Skip to first unread message

Jason Moseley

unread,
Feb 4, 2004, 11:56:39 AM2/4/04
to
Does anyone know how to clear the current user view in a dos screen
while a vbscript is running?
For instance: If a user selects an option from a menu, clear the menu
and start the clear screen with their option...

Thanks in advance....

Ray at <%=sLocation%> [MVP]

unread,
Feb 4, 2004, 12:01:34 PM2/4/04
to
What menu? What DOS screen? What do you mean? CLS is the clear screen
command in DOS/shell scripting. ?

Ray at work

"Jason Moseley" <greennin...@hotmail.com> wrote in message
news:%23LG0c$z6DHA...@TK2MSFTNGP11.phx.gbl...

Jason Moseley

unread,
Feb 4, 2004, 12:15:33 PM2/4/04
to

I know I can use CLS to clear a dos screen, but how do I implement that
into a vbscript? When I say menu, I mean it's just a dos echo of
options which the user just picks from.

Ray at <%=sLocation%> [MVP]

unread,
Feb 4, 2004, 12:44:44 PM2/4/04
to
Why don't you just use CLS then if the user is interacting with dos?

@echo off
:Select
echo Please select your option.
echo.
echo 1. Pears
echo 2. Grapes
echo 3. Doritos
echo 4. Pineapple
echo.
SET /P NumSelect=Enter number:
SET /A NumSelect=%NumSelect%
IF %NumSelect%==0 GOTO :Select
IF %NumSelect% GTR 4 GOTO :Select
echo You selected option %NumSelect%
pause
CLS

Ray at work

"Jason Moseley" <greennin...@hotmail.com> wrote in message

news:%23Cx3AK0...@TK2MSFTNGP12.phx.gbl...

mr unreliable

unread,
Feb 4, 2004, 1:07:06 PM2/4/04
to
hi Green Ninja,

Try this:

oShell.Run "%comspec% /c CLS"

cheers, jw

"Jason Moseley" <greennin...@hotmail.com> wrote in message

news:%23Cx3AK0...@TK2MSFTNGP12.phx.gbl...

Richard Mueller [MVP]

unread,
Feb 4, 2004, 1:30:55 PM2/4/04
to

"Jason Moseley" <greennin...@hotmail.com> wrote in message
news:%23Cx3AK0...@TK2MSFTNGP12.phx.gbl...
Hi,

I tried and was unable to do it, using the WshShell object's Run and
AppActivate methods. Each ran cls (or a batch file) in another thread.

I would suggest putting your menu program in a batch file. Either run it
directly, or use the Run method to launch it from a VBScript. The program
will run in another DOS window, but you can do what you want there, then
exit and return to where ever you came from (the first DOS window or what
ever). I assume you have figured out how to accept input from the user at a
command prompt. I used to use assembly language tools for that, but there
might be better ways now.

Of course, you could display the menu selections with InputBox in VBScript,
but I assume your menu is too large.

strAns = InputBox("Select an option by number:" _
& vbCrLf & vbCrLf & "1: First" _
& vbCrLf & "2: Second" _
& vbCrLf & "3: Third", "Menu")

Wscript.Echo strAns

There are also options using the IE object in VBScript if you really want to
get fancy. If this interests you, do a Google Advanced Group search in the
scripting newsgroups, searching on "InternetExplorer.Application".

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--


Michael Harris \(MVP\)

unread,
Feb 4, 2004, 11:20:52 PM2/4/04
to


Script executed via cscript has no way of communicating with the command
shell that is providing the console window to ask it to execute the command
shell's *internal* CLS command. There was a very lengthy thread on this
topic a couple of years ago with a lot of people trying a lot of things, all
to no avail...


--
Michael Harris
Microsoft.MVP.Scripting

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp

TechNet Script Center Sample Scripts
http://www.microsoft.com/technet/scriptcenter/default.asp
Download in HTML Help format (searchable and indexed)
http://www.microsoft.com/downloads/release.asp?ReleaseID=38942

WSH 5.6 documentation download
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

Michael Schipp

unread,
Feb 4, 2004, 11:58:18 PM2/4/04
to
Here is a VERY BAD way of doing it if you must.

'Code start
wscript.echo "hello all"
dim astr, loop1, loop2
for loop1 = 1 to 25
for loop2 = 1 to 80
astr = astr & " "
next
next

wscript.echo astr
'Code end

Thank you,
Michael

"Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
news:eMFcy956...@TK2MSFTNGP10.phx.gbl...

Al Dunbar [MS-MVP]

unread,
Feb 5, 2004, 1:37:21 AM2/5/04
to
Not as bad as:

wscript.echo "I can't clear the screen - but you can"
wscript.echo "just turn of your monitor!"


/Al

"Michael Schipp" <msc...@asi.com.au.SPAMmenot> wrote in message
news:%23%23iEuS66...@TK2MSFTNGP09.phx.gbl...

Tom Lavedas

unread,
Feb 5, 2004, 10:58:09 AM2/5/04
to
The short answer is 'it can't be done'.

However, with WSH v5.6, you can approximate it pretty well
with the routine that I posted and explained here:

http://www.google.com/groups?selm=575601c3db01%2467878210%
247d02280a%40phx.gbl

(URL is all one line, but wrapped in Email)

That posting is of a routine I called CEcho.vbs. It makes
heavy use of environment variables to set script
parameters. It was really written to allow the use of
colors when sending output to the command prompt console
from a batch procedure under Win NT/2K/XP. It was made to
be used as part of a WSH script. It does contain two
subroutines that can be used in scripts, however, WriteXY
and ClearScreen. Still, these were not completely self
contained, as they assumed the presence of an oExec
object, instantiated before the routines are called. That
posting does provide a prototype script framework for what
you want to do, if you're willing to work with it.

You would need to remove the command line argument
handling features and instead provide the necessary
parameters to the subroutines. The biggest difference
between th approach implemented in the ClearScreen()
routine and the command prompt's CLS is that it cannot
reset the command line cursor to the top of the screen.
Thus, the need for the WriteXY routine, which instruments
putting text anywhere on the screen (and in any color).

The two routines could be made 'standalone' by moving the
instanciation of the WShell.Exec object into the
subroutines, but I had opted for overall effeciency when
making multiple calls to the write routines, instead.

One thing I haven't played with is insrumenting user
interaction in this context. I can be done, but is
probably best done using the FSO to open the CON device to
receive user input. as in ,,,

With CreateObject("Scripting.FileSystemObject")
s = .OpenTextFile("CON", 1).ReadLine
End with

For a single letter input, change the ReadLine to Read().

One example that I have played with is this box drawing
routine (which is probably too long to post here, but I'm
doing it anyway).

------------------8<-----------------
' A console box drawing routine
'
' ------- Start Main -------
Dim oExec, HexColor, x, y, text

Const cCLS = "FB800:0 L 2000 "
Const black = 0, blue = 1, green = 2, cyan = 3, _
red = 4, violet = 5, brown = 6, grey = 7, _
bblack = 8, bblue = 9, bgreen = "A", bcyan = "B", _
bred = "C", bviolet = "D", yellow = "E", white = "F"
Const cHor = "Ä", cVert = "³"
Const cULCorner = "Ú", cURCorner = "¿", _
cLLCorner = "À", cLRCorner = "Ù"

set fso = CreateObject("Scripting.FileSystemObject")
fso.OpenTextFile("CON", 2).WriteBlankLines 42

' Defaults
Color = white & black
x1=0 : y1=0: x2=79 : y2=42
fill = false
text=""

Do
if wscript.Arguments.Count = 0 Then
' Read keyboard
wsh.echo
wsh.stdOut.Write "Input: "
s = fso.OpenTextFile("CON", 1).ReadLine
for each arg in Split(s, "//")
Execute replace(arg, "'", Chr(34))
next
Else
' Read command line
for each arg in wscript.Arguments
Execute replace(arg, "'", Chr(34))
next
s = "Q" ' Do not loop, if run with commandline args
End if
HexColor = Right("0" & Color, 2)
' Start the Debug.exe program
Set oExec = CreateObject("WScript.Shell")_
.Exec("%comspec% /c debug ")

' Wait for Debug.exe to load
Do Until oExec.StdOut.Read(1) = "-"
wsh.sleep 10
Loop

if Ucase(text) = "CLS" then ClearScreen Color, "20"

' Draw Box
for v = y1+1 to y2-1
WriteXY x1, v, HexColor, cVert 'chr(179)
if fill then _
WriteXY x1 + 1, v, HexColor, String(ABS(x2 - x1)-
1, " ")
WriteXY x2, v, HexColor, cVert 'chr(179)
Next
WriteXY x1, y1, HexColor, _
cULCorner & String(ABS(x2 - x1)-1, cHor) & cURCorner
WriteXY x1, y2, HexColor, _
clLCorner & String(ABS(x2 - x1)-1, cHor) & clRCorner

' Quit Debug.exe
oExec.StdIn.Writeline "e0:451 2A"
oExec.StdIn.Writeline "q"

if wscript.Arguments.Count = 0 Then
' Pause if run with keyboard input
s = fso.OpenTextFile("CON", 1).Read(1)
End if
Loop Until s=vbCR or Ucase(s)="Q"
' -------- End Main ---------

Sub WriteXY(X, Y, hColor, sText)
Dim ColorText
For j = 1 to Len(sText) Step 10
ColorText = "EB800:" & Hex(Y * 160 + (X + j - 1) * 2)
For i = j to j + 9
ColorText= ColorText & " " _
& Hex(Asc(Mid(sText, i, 1))) & " " & hColor
if i = Len(sText) Then Exit For
Next
oExec.StdIn.Writeline ColorText
Next
End Sub

Sub ClearScreen(hColor, cChr)
oExec.StdIn.Writeline cCLS & cChr & " " & hColor
End Sub
-----------------8<------------------

Too much said, so I'll stop now.

Tom Lavedas
===========

0 new messages