An OCX-less Progress Bar

An OCX-less Progress Bar

If you need a progress bar in your VB6 application, but don’t want to add the reference to Microsoft Windows Common Controls, here’s a simple way to create a progress bar that doesn’t require any extra components.

Author’s Note: The sample program does use the slider bar from the Common Controls, but only for demonstration purposes—the slider control isn’t required to implement the solution.

The trick is to use a VB6 line control, and then vary the length of the line to simulate a progress bar. You can get fancy with the bar’s color or width. With some minor code changes, you can easily create a vertical rather than horizontal progress bar.

To set up the demo, go into VB and create a new project. For demonstration purposes only, add a reference to the Microsoft Windows Common Controls, and add a slider bar to the bottom of the form. Resize the slider bar so it fits across the form.

Paste the following code into the default form:

Option ExplicitDim RightMost As LongDim Line1 As ControlPrivate Sub Form_Load()    'This section adds a line control to the form.    Set Line1 = Form1.Controls.Add("VB.Line", "Line1", Form1)    Line1.X1 = 240    Line1.X2 = 4080    Line1.Y1 = 1080    Line1.Y2 = 1080    Line1.Visible = True    'Save the rightmost point.    RightMost = Line1.X2    Line1.BorderWidth = 4        'The fun part is here.    Slider1.Max = 100    Slider1.Min = 1End SubPrivate Sub Slider1_Change()    Call NewBar(Slider1.Value)End SubPrivate Sub NewBar(XPercent)    Line1.X2 = (RightMost - Line1.X1) * (XPercent / 100)    If Line1.X2 < Line1.X1 Then Line1.X2 = Line1.X1End Sub

Now run the program. As you slide the indicator across the screen, you'll see the line change to match the indicator.

Author's Note: If you add the line control to the form at design time, you can remove the Form_Load code down to the "Save the rightmost point" comment.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several