Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Math with time
Message
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00327347
Message ID:
00328345
Vues:
19
>Anyone doing any math with time?
>
>Say I wanted to time out a form. I call my foo sub and want to time this form out in approx (dynamic) minutes. Say I call the (VB time function) and try to say MyTimeOut time = (VB time function) + (dynamic) minutes. Then in the form I can ease the system strain by setting my timer to check the actual time every 65 seconds for (VB Time function) to => MyTimeOut vice an incrementer variable.
>
>I have tried a number of methods and it apears that i have missed the boat. I Realize that this is a little academic :) but does any one have any ideas.

I already used this. Maybe it can help!

On a form, add a Timer control (named tmrIdleDetect), set its Interval property to what ever you want greater than 0 (60000 is a good choice) and paste this code:
Private Sub tmrIdleDetect_Timer()
' IDLEMINUTES determines how much idle time to wait for before
' running the IdleTimeDetected subroutine.
Const IDLEMINUTES = 10
Static strPrevControlName As String
Static strPrevFormName As String
Static sngExpiredTime As Single
Dim strActiveFormName As String
Dim strActiveControlName As String
Dim sngExpiredMinutes As Single

    'Only effective between 10PM and 6AM
    If Not (Now > CDate(DateSerial(Year(Date), Month(Date), Day(Date)) & " " & TimeSerial(22, 0, 0)) And _
            Now < CDate(DateSerial(Year(Date), Month(Date), Day(Date) + 1) & " " & TimeSerial(6, 0, 0))) _
    Then
        Exit Sub
    End If
    
    On Error Resume Next
    
    ' Get the active form and control name.
    strActiveFormName = Screen.ActiveForm.Name
    If Err.Number Then
        strActiveFormName = "No Active Form"
        Err.Clear
    End If
    strActiveControlName = Screen.ActiveControl.Name
    If Err.Number Then
        strActiveControlName = "No Active Control"
        Err.Clear
    End If

    ' Record the current active names and reset ExpiredTime if:
    '    1. They have not been recorded yet (code is running
    '       for the first time).
    '    2. The previous names are different than the current ones
    '       (the user has done something different during the timer
    '        interval).
    If (strPrevControlName = "") Or _
       (strPrevFormName = "") Or _
       (strActiveFormName <> strPrevFormName) Or _
       (strActiveControlName <> strPrevControlName) _
    Then
        strPrevControlName = strActiveControlName
        strPrevFormName = strActiveFormName
        sngExpiredTime = 0
    Else
    ' ...otherwise the user was idle during the time interval, so
    ' increment the total expired time.
        sngExpiredTime = sngExpiredTime + tmrIdleDetect.Interval
    End If
    
    ' Does the total expired time exceed the IDLEMINUTES?
    sngExpiredMinutes = (sngExpiredTime / 1000) / 60
    If sngExpiredMinutes >= IDLEMINUTES Then End
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform