Solved

Terminal progressbar in vbs vbscript

Posted on 2014-03-04
2
813 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
2 Comments
 
LVL 14

Accepted Solution

by:
sentner earned 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

839 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