Created: April 10, 1995
When a Visual Basic® program is executing a time-consuming task, you can display the progress of that task by using a status bar in the program. This article explains how you can use a three-dimensional control to add this feature to your Visual Basic programs.
To add a status bar to your Visual Basic® program, you use a three-dimensional (3D) Panel control. Your program displays a blue horizontal bar that is filled from left to right. As your program updates the percentage-completed variable, the 3D Panel is also updated. In the example program below, we set the X variable equal to the number of bytes in the TEST.COM file. As each block of 100 bytes is read from the file, the FloodPercent property of the 3D Panel control is adjusted accordingly. This is how the horizontal bar appears to grow from left to right until the entire file has been processed.
The following program shows how you can add a percentage-completed status bar to your own Visual Basic application. It is assumed that you have a temporary file called TEST.COM in the root directory of drive C. As this program reads data from the temporary file, it displays the percentage completed on the status bar. The program ends when the entire file has been processed, showing a "100 percent completed" message in the status bar.
Sub Command1_Click()
Dim inp As String * 100
x = FileLen("c:\test.com")
Open "c:\test.com" For Binary As #1
Label1 = "Working..."
Label1.Refresh
i = 0
While Not EOF(1)
Get #1, , inp
i = i + 100
Panel3D1.FloodPercent = 100 * i / x
Text1 = inp
Wend
Close #1
Label1 = "Done"
End Sub
Knowledge Base Q113999. "How to Create a Setup-Like Status Bar in Visual Basic." (Development Library, Knowledge Base and Bug Lists)