If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
I have set Max as 50 and Min as 0 and the code is this
Private Sub Timer1_Timer()
PB.Value = PB.Value + 1 -> (After pb reaches max it displays as per code but then shows the run time error highlighting this line of code)
If PB.Value = 5 Then Label3.Visible = True
If PB.Value = 10 Then Label3.Visible = False
If PB.Value = 15 Then Label3.Visible = True
If PB.Value = 20 Then Label3.Visible = False
If PB.Value = 25 Then Label3.Visible = True
If PB.Value = 30 Then Label3.Visible = False
If PB.Value = 35 Then Label3.Visible = True
If PB.Value = 45 Then Label3.Visible = False
If PB.Value = 49 Then
Label3.Visible = True
PB.Visible = False
Label5.Visible = False
End If
End Sub
I think I understand the problem now. You assigned min and max through the control properties.
When you do that, you are setting the valid range, but that doesn’t stop you from trying to assign values outside that range, so you have to make sure that doesn’t happen.
You have to check the value you are going to assign. Something like this:
Private Sub Timer1_Timer()
If PB.Value < PB.max Then
PB.Value = PB.Value + 1 -> (After pb reaches max it displays as per code but then shows
Else
'Something else
End If
If PB.Value = 5 Then Label3.Visible = True
...
...
End Sub
I have given range 0 to 50. The code “Pb.value=pb.value+1 is highlighted as run time error
We would need to see the complete code to try to help.
Are you sure the loop is not going farther than 100 interations ?
To debug it, try adding some code like this, replacing the line that is causing the error:
If Pb.value >= 100 then MsgBox("Value is already 100") else Pb.value=pb.value+1 End IfI have set Max as 50 and Min as 0 and the code is this
Private Sub Timer1_Timer()
PB.Value = PB.Value + 1 -> (After pb reaches max it displays as per code but then shows the run time error highlighting this line of code)
If PB.Value = 5 Then Label3.Visible = True
If PB.Value = 10 Then Label3.Visible = False
If PB.Value = 15 Then Label3.Visible = True
If PB.Value = 20 Then Label3.Visible = False
If PB.Value = 25 Then Label3.Visible = True
If PB.Value = 30 Then Label3.Visible = False
If PB.Value = 35 Then Label3.Visible = True
If PB.Value = 45 Then Label3.Visible = False
If PB.Value = 49 Then
Label3.Visible = True
PB.Visible = False
Label5.Visible = False
End If
End Sub
I think I understand the problem now. You assigned min and max through the control properties.
When you do that, you are setting the valid range, but that doesn’t stop you from trying to assign values outside that range, so you have to make sure that doesn’t happen.
You have to check the value you are going to assign. Something like this:
Thank you that solved my problem