Solved

Terminal progressbar in vbs vbscript

Posted on 2014-03-04
2
735 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
Comment Utility
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
Comment Utility
Yes, you are right.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now