Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Terminal progressbar in vbs vbscript

Posted on 2014-03-04
2
Medium Priority
?
955 Views
Last Modified: 2014-03-07
This is a progressbar. The script is run with cscript.

progtressMax is defined outside the function and is global. For instance 30.
Function DisplayProgress(progressNumber)
	On Error Resume Next
	Dim percentDone, percentLeft, intCount
	'oShell.SendKeys "CLS + {ENTER}" 
	oShell.Run "cls" 
	progressCount = progressCount + progressNumber
	wScript.StdOut.Write("|")
	percentDone = round((progressCount / progressMax) * 100)
	For intCount = 0 To percentDone
		wScript.StdOut.Write(".")
	Next
	percentLeft = round(100-((progressCount / progressMax) * 100))
	For intCount = 0 To percentLeft
		wScript.StdOut.Write("_")
	Next
	wScript.StdOut.Write("|")
End Function

Open in new window


The problem is that I am not able to clear the screen at the start of the function. So the progressbar floods the screen without making any sense.

Is there a better way to make a terminal progressbar? I don't want html and I don't want popups. Is there a way that works to clear the screen? Please don't post links to other pages of code unless you have tested and verified that it works. The above code for clearing does not work, and there are several examples out there of code that does not work.
0
Comment
Question by:itnifl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
sentner earned 2000 total points
ID: 39903481
You don't actually need to clear the screen between every update, just move the cursor back to the beginning of the line.  

Remove the "cls" line (not needed).
Replace line 7 above with:
      wScript.StdOut.Write chr(13) + "|"

Do note that the terminal is only 80 characters wide by default, so you may need to do some extra math to make the maximum width of the bar fit in the window.
0
 
LVL 2

Author Closing Comment

by:itnifl
ID: 39912806
Yes, you are right.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question