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:
Share on facebook
Share on twitter
Share on linkedin


The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a