i simple want progressbar should execute until it becomes 100 after some interval.but it is not working properly.can anyone help me .Any help would be Greately appreciated.Here is the code what i have written.

Private Sub Timer1_Timer()
For i = 10 To 100 Step 10
ProgressBar1.Value = CInt(i)
If ProgressBar1.Value = 100 Then
Unload Me
Load MDIForm1
MDIForm1.Show
End If
Next i
End Sub

Private Sub Command1_Click()
   If Text1.Text = "" And Text2.Text = "" Then
   MsgBox "Password mismatch", vbInformation, "Retype"
   Text1.Text = ""
   Text2.Text = ""
   Text2.SetFocus
   End If
   If Text1.Text <> "" And Text2.Text <> "" Then
   Set rs = New Recordset
   rs.Open "select * from Employees_DB_Access where EMP_ID=" & Text1.Text, con, adOpenDynamic, adLockOptimistic
   If rs.EOF Then
   MsgBox "User ID Mismatch", vbInformation, Me.Name
   Text1.Text = ""
   Text1.SetFocus
   ElseIf Text1.Text = rs.Fields(0) And Text2.Text <> rs.Fields(1) Then
   MsgBox "Password is invalid", vbInformation, Me.Name
   Text2.Text = ""
   Text2.SetFocus
   ElseIf Text1.Text <> rs.Fields(0) And Text2.Text = rs.Fields(1) Then
   MsgBox "Invalid User ID", vbInformation, "retype"
   ElseIf Text1.Text = rs.Fields(0) And Text2.Text = rs.Fields(1) Then
   ProgressBar1.Visible = True
   Timer1.Enabled = True
   Exit Sub
   Else
   MsgBox "User ID Mismatch", vbInformation, "retype"
   Text1.Text = ""
   Text2.Text = " "
   Text1.SetFocus
   Exit Sub
   End If
   End If
'  rs.Close
   End Sub

Recommended Answers

All 5 Replies

Okay, right of the bat I can see a potential problem with your timer control and its sub procedure. Not knowing, as I only read the first few lines, what your timer interval is set at I can guess that it may be way too low causing a problem called reentrancy, which means that the first time the timer is called, if the code inside the timer does not complete before the timer is triggered again, then you have the same code starting to execute again. The second thing that I see wrong with the code inside the timer is that you try to unload the form but you do not stop the timer by setting its enable property to false or by setting its interval property to zero. Now you can do this in the form unload event but I don't see that code posted.

So here is what seems to be happening with your code. The form displays, the timer triggers, and lickity split the progress bar reads 100% and you unload the form. Problem is, the timer activates again thus reloading the form and starting the process all over again in an endless loop.

So how to fix this...

There are a couple of ways and what follows is just one.

First you could use a variable declared at form level...

Option Explicit

Dim TimerCounter As Integer

Then in your form load event you setup your timer and progress bar

Private Sub Form_Load()

ProgressBar1.Min = 0
ProgressBar1.Max = 100

Timer1.Interval = 100
Timer1.Enable = True

End Sub

Followed by the timer event itself

Private Sub Timer1_Timer()

'Prevent reentrancy issues by disabling the timer
Timer1.Enable = False

'increment, update
TimerCounter = TimerCounter + 10
ProgressBar1.Value = TimerCounter

'test to see if we have reached the max (100)
If TimerCounter = 100 Then
  'ok, we have reach the max so unload and exit
  Unload Me
  Exit Sub
End If

'If we made it here then we have not reached max so we need to reenable the timer
Timer1.Enabled = True

End Sub

Now the above will take about 1 second and if you want to make it last longer just increase the interval (1000 = 1 second)

Good Luck

comment Unload Me in your code and i hope the rest wills tart working. use Me.Hide instead of unload Me.

system hangs when i comment .unload me and replace me.hide.here is the code what i have written.

Private Sub Timer1_Timer()
For i = 100 To 1000 Step 10
ProgressBar1.Value = CInt(i)
If ProgressBar1.Value = 1000 Then
 Me.Hide
'Unload Me
Load MDIForm1
MDIForm1.Show vbModeless
End If
Next i
End Su

comment Unload Me in your code and i hope the rest wills tart working. use Me.Hide instead of unload Me.

I take it you did not read my post too well...

Thank you Vb5 Programmer.now i assign timer interval 1000 for 10 seconds.min value for progressbar=0 and max value=100.Now it
is working fine.Here is the code what i have written as per your
suggestion.

Private Sub Timer1_Timer()
 'For i = 10 To 100 Step 10
  ProgressBar1.Value = ProgressBar1.Value + 10
  If ProgressBar1.Value = 100 Then
     Unload Me
     Load MDIForm1
     MDIForm1.Show
  End If
 'Next i
End Sub
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.