ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
Posted by Daniel - 11,382 Views
It is good to know that long process is still ticking and one of the best way to provide the indicator is to have a progress bar. I am pretty sure you already knew how to display progress bar when you deal with windows form application but what about console application, is there any progress bar component which can be easily incorporated into the console screen?
I’ve searched the internet to find this kind of stuff but I found nothing (let me know if I am wrong), so there is no other way than to create it myself and here it is: my own progress bar for console application written in VB.Net.
It’s very simple. I use a single sub procedure instead of packing it as a class since I don’t think it’s required. A sub procedure called RenderProgressBar is the only procedure responsible to process and render the progress bar on the console screen.
There are two options you can use with this function. The first one is to display the progress bar with maximum limit specified. With this option the percentage of process and the “bar” itself will be displayed. The second one is displaying the progress without specifying the max limit so there is no “bar” with this option, it will only display the iteration value - it’s good when you have no idea when a process will be completed but you still want to show that the process is still ticking.
Following is the RenderProgressBar code:
Dim strResult As String
Dim intPercent As Integer
If (intMaxValue > 0) Then
intPercent = Math.Round((intProgress / intMaxValue) * 100, 0)
If intPercent >= 10 Then
strResult = “| “ & intPercent & “% |” & StrDup(intPercent \ 10, “=”) & StrDup(10 - (intPercent \ 10), ” “) & “|”
Else
strResult = “| “ & intPercent & “% |” & StrDup(10, ” “) & “|”
End If
Else
intPercent = intProgress
strResult = “| “ & FormatNumber(intPercent, 0) & ” |”
End If
Console.CursorVisible = False
Console.SetCursorPosition(intLeftPos, intTopPos)
Console.Write(strResult)
Console.CursorVisible = True
End Sub
The demo project along with the RenderProgressBar sub procedure is included in this post. Feel free to enhance this function as you wish, in fact I encourage you to do it. You may pack it as a class or anything as long as it gets better. Good luck :)
Available Download:
The following posts are programmatically considered as related to the current post by YARPP Plugin:
- Passing arguments to your VB.NET console application
- How to Get User Input and allowing more than 256 characters to be entered on .NET Console Application
- Bringing the Lovely VBScript Split Function into Delphi with a Custom Function
- Runtime-Form-Creation. Automatically creating child forms in a Delphi MDI application with a component array
- Visual Basic.NET, an example of using HTTPWebRequest object
One Response to “ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application”
Leave a Reply
Hi, my name is Daniel Nugraha, a single male live on an island called Java, Indonesia. This is the place for me to share my interest in computer programming.
-
Get my Full Feed Here
Comments - Thanks Guys :)
Rangga Kusuma: Gan, Tengkiu buat postingan yang sangat berguna. Kebetulan ada project utk bikin sms gateway, dan converter Agan sangat berguna utk...
Chuck Norton: I actually went ahead & bolted over to Justin’s Get The Image plugin here: http://justintadlock.com/ar...
Chuck Norton: Question: is it possible to insert something like [custfieldimg=”joice1.jpg,15 0,1:1″] into the actual templates instead of...
Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.














March 16th, 2008 at 5:51 am
Nice tip, nice snippet. Console apps rock!
JohnnyIdol’s last blog post: [C++] How to disable Alt+Tab (and other key combinations)