to set interval time over 1 minute with VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bero81
    New Member
    • Dec 2006
    • 8

    to set interval time over 1 minute with VB6

    I have to set the interval time,over one minute in vb6.
    the point is,i set the inteval at 1 minute and write down:
    timer1.interval =60000,because 1 minute is 60000,
    but when i do the same thing for 2 minutes i write down timer1.inteval= 120000,and i've got the problem "Invalid property value"....how can i sort that problem out ?????

    Thanks a lot to everybody...
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by bero81
    I have to set the interval time,over one minute in vb6.
    the point is,i set the inteval at 1 minute and write down:
    timer1.interval =60000,because 1 minute is 60000,
    but when i do the same thing for 2 minutes i write down timer1.inteval= 120000,and i've got the problem "Invalid property value"....how can i sort that problem out ?????

    Thanks a lot to everybody...
    The timer interval can only be set to a number between 0 and 65,536. If you need two minutes, just set it to 60,000 and wait until it triggers twice.

    For example, one way would be to define a static variable in the Timer event routine, and set it to the last time the event was triggered. If the last time was less than 2 minutes ago, just Exit Sub.

    Comment

    • hariharanmca
      Top Contributor
      • Dec 2006
      • 1977

      #3
      Originally posted by bero81
      I have to set the interval time,over one minute in vb6.
      the point is,i set the inteval at 1 minute and write down:
      timer1.interval =60000,because 1 minute is 60000,
      but when i do the same thing for 2 minutes i write down timer1.inteval= 120000,and i've got the problem "Invalid property value"....how can i sort that problem out ?????

      Thanks a lot to everybody...
      Or Simply you can use a Flag as Integer

      when the Timer reaches 60,000 then increase the flag value as
      flag+=1 '.Net
      flag=flag+1 'VB6

      then check the Condition for flag=2...

      Now, I think your problem is Solved

      Comment

      • bero81
        New Member
        • Dec 2006
        • 8

        #4
        Originally posted by Killer42
        The timer interval can only be set to a number between 0 and 65,536. If you need two minutes, just set it to 60,000 and wait until it triggers twice.

        For example, one way would be to define a static variable in the Timer event routine, and set it to the last time the event was triggered. If the last time was less than 2 minutes ago, just Exit Sub.



        Could you write down the example of the code for setting the interval every two minute?Please.. .
        Thanks a lot.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by bero81
          Could you write down the example of the code for setting the interval every two minute?Please.. .
          Code:
          Private Sub Timer1_Timer()
          
          
            ' [B]hariharanmca's version...[/B]
            Static Flag As Integer
            Flag = Flag + 1
            If Flag < 2 Then
              Exit Sub
            End If
            Flag = 0 ' Don't forget to reset it here.
          
          
            ' [B]My version...[/B]
            Static LastTriggered As Date
            If DateDiff("s", LastTriggered, Now) < 120 Then
              Exit Sub
            End If
            LastTriggered = Now
          
          
            [B]< Insert your code here>[/B]
          
          
          End Sub
          You can easily avoid using the DateDiff function if it bothers you.

          Comment

          • hariharanmca
            Top Contributor
            • Dec 2006
            • 1977

            #6
            Originally posted by Killer42
            Code:
            Private Sub Timer1_Timer()
            
            
              ' [B]hariharanmca's version...[/B]
              Static Flag As Integer
              Flag = Flag + 1
              If Flag < 2 Then
                Exit Sub
              End If
              Flag = 0 ' Don't forget to reset it here.
            
            
              ' [B]My version...[/B]
              Static LastTriggered As Date
              If DateDiff("s", LastTriggered, Now) < 120 Then
                Exit Sub
              End If
              LastTriggered = Now
            
            
              [B]< Insert your code here>[/B]
            
            
            End Sub
            You can easily avoid using the DateDiff function if it bothers you.


            Thank You Killer42 forgot to Inform reset Flag Val,

            Comment

            • bero81
              New Member
              • Dec 2006
              • 8

              #7
              Originally posted by hariharanmca
              Thank You Killer42 forgot to Inform reset Flag Val,

              Thanks a lot, it works!!!!!!!!!! !!!!

              c u....

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by bero81
                Thanks a lot, it works!!!!!!!!!! !!!!
                Glad to hear it.

                Keep in mind that you only need one of those two code blocks - mine or the other one. They both do roughly the same thing.

                Comment

                • BACKPACK
                  New Member
                  • Oct 2008
                  • 1

                  #9
                  I am having similar problems.

                  I intend to run a code, and it works when I use:

                  Private Sub Timer1_Timer()

                  'If Text9.Text = "" Then MsgBox "enter a time value": End
                  'Timer1.Interva l = Int(Text9.Text)
                  'Timer1.Enabled = True
                  or

                  'If Text9.Text =1000 Then
                  'Timer1.Interva l = Int(Text9.Text)
                  'Timer1.Enabled = True
                  Endif

                  .....
                  .....
                  ...

                  'End Sub


                  But I need to run it hourly. so I tried to use one of:

                  1. Private Sub Timer1_Timer()
                  2.
                  3.
                  4. ' hariharanmca's version...
                  5. Static Flag As Integer
                  6. Flag = Flag + 1
                  7. If Flag < 2 Then ‘2 minutes
                  8. Exit Sub
                  9. End If
                  10. Flag = 0 ' Don't forget to reset it here.
                  11.
                  12.
                  13. ' My version...
                  14. Static LastTriggered As Date
                  15. If DateDiff("s", LastTriggered, Now) < 120 Then ‘ie 2MINUTES
                  16. Exit Sub

                  16. Exit Sub
                  17. End If
                  18. LastTriggered = Now
                  19.
                  20. Flag = 0
                  21. < Insert your code here>

                  and I still have problems.

                  Please help.

                  Comment

                  Working...