I wanted to add a loading screen to my program.

My code is

Private Sub Timer1_Timer()
    Dim x As Integer
    x = 1
     If Me.ProgressBar1 >= 10 Or x >= 10 Then
        Unload Me
        MDIForm1.Show
        Timer1.Enabled = False
    Else
        
        x = x + 1
        x = Me.ProgressBar1
    
   End If
End Sub

It doesn't work. Whats wrong with my code?

It's been a while since I played in VB,
but doesn't the x = 1 run every time the timer is called?

The sub as displayed reads from Me.ProgressBar1 , but does not appear to set it, so the value doesn't change here.

So if neither Me.ProgressBar >= 10 or x >= 10 will ever be true, I wouldn't expect the 'loading' window to ever close.

Ah thanks. It solve the problem.

Private Sub Timer1_Timer()
ProgressBar1.Value = ProgressBar1.Value + 5
    If ProgressBar1.Value = 100 Then
        MDIForm1.Show
        Timer1.Enabled = False
        Unload Me
    End If
End Sub

Set Timer Interval on Properties = 70.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.