Results 1 to 11 of 11

Thread: Timer

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    13

    Post

    Hi, I'm new to programming in VB so I hope you could help me with my problem.

    In my first VB-project, I've made a timer with a interval=100 and then I've done some if-statements, like if the timer < 25 say this and so on, but it doesn't function, any ideas?

    I haven't sat any start value, because it doesn't seem to work in VB 4.0.

    Osborn
    VB6 SP3 user

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    I think you are using the timer incorrectly.

    assuming you mean a timer control, setting the interval to 100 just means the the timer event is triggered every 1/10 of a second.

    Let me know waht it is you are tring to do and I'll see if I can help.
    Mark
    -------------------

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    13

    reply

    I'm trying to do a program that is going to say something dependent on how long time the timer has gone.

    If it has gone less than 25 then say that, in a messagebox and if it has gone between 25 and 50 say that in the msgbox, so the msgbox will be updated depending on how long time it has gone.

    example:

    Code:
    if Timer1 < 10 then
    MsgBox "blah blah"
    end if
    if Timer1 > 10 and Timer1 < 15 then
    MsgBox "blah blah2"
    end if
    I sat the intervall to 100. It seems that I have to write Timer1.value, but that doesn't work, neither Timer1.min or timer1.max in the form_load either.

    Any suggestions?

    Thanks for your help.
    Osborn
    VB6 SP3 user

  4. #4
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136
    In your timer event, you need to check the System time and compare that with the time at which the program was executed. The timer control can't really be used as an internal counter - all it does, as Mark Sreeves said, is trigger the code in your timer event every x milliseconds.

  5. #5
    Addicted Member
    Join Date
    Mar 2000
    Posts
    168

    heres an idea

    set your timer intervals to 1000 (that is about equiv to one second).. in your general declarations declare a variable like so..

    Code:
    'In general declarations
    Dim TimePassed As Long
    
    'In timer event
    TimePassed = TimePassed + 1
    
    If TimePassed > 25 Then
      'Do whatever
    End If
    Also keep in mind where you wish to set your TimePassed variables to 0, whether in the form load or whatever, depending on when the timer becomes active. Its early and I'm not awake, this all might not make sense :P Let me know if you have questions.

    Thai


  6. #6

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    13

    Unhappy

    Thai and all you others who has tried to help me; Thanks!

    Thai, I'm quite new at this, so could you explain what you meant, I didn't understand really.

    Thanks in advance!

    -Osborn -q-

  7. #7
    Addicted Member
    Join Date
    Mar 2000
    Posts
    168
    The code I gave was a basic way to have the timer act when X amount of seconds have gone by, since I don't know exactly what you are trying to accomplish it is hard for me to help you further, reply and let me know what your objective is in this project or this function and I'll assist you in getting it done.

    Thai

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    13

    Post

    My objective with this first program is that it would dispaly different types of messages depending on how long time that has passed.

    Like when you install a progam you see what sort of files that are installed and how long time that has passed. I want something like that, but just that it will change message in a msgbox depending on how long time that has passed and I don't need to know how long time that has passed from the counting.

    Can't you use something like timer1.value or start value or max value or something like that?

    Osborn
    VB6 SP3 user

  9. #9
    Addicted Member
    Join Date
    Mar 2000
    Posts
    168
    No you must declare a variable to keep track of the time passed since the timer object does not have a min, max, or value property to it. Anyway, this is one way you could do it.

    Code:
    'In the general declarations
    Private TimePassed As Long
    
    'In the Form_Load event
    Timer1.Interval = 1000
    Timer1.Enabled = True
    TimePassed = 0
    
    'In the Timer1_Timer event
    TimePassed = TimePassed + 1
    
    Select Case TimePassed
      Case Is = 30
        MsgBox "30 seconds have passed."
      Case Is = 60
        MsgBox "60 seconds have passed."
    End Select
    Then you can add as many Cases as you wish, I think this is what you're looking for.

    Thai

  10. #10
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    more accurate

    Hi Osborn, if you need a good accuracy result, then may be you should use the GetTickCount API function instead os using the timer to increase a variable.

    Code:
    Option Explicit
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Dim T1&, T2&
    Private Sub Form_Load()
    Timer1.Interval = 1000
    Timer1.Enabled = True
    T1 = GetTickCount()
    T2 = 0
    End Sub
    
    Private Sub Timer1_Timer()
    T2 = GetTickCount()
    Label1.Caption = (T2 - T1) / 1000 & " milisecond have passed..."
    End Sub

  11. #11

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    13

    Smile

    Thank you all for the help, the problem is now solved thanks to you!

    Thai, I used what you said and it worked out fine.

    Osborn -q

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width