Solved

Terminal progressbar in vbs vbscript

Posted on 2014-03-04
2
868 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

728 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