Results 1 to 4 of 4

Thread: < Hanging On [Timer Problem] >

  1. #1

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    < Hanging On [Timer Problem] >

    Code:
    '  Problem:
    '  Before I fire I can access other features 
    '  After I fire and set the form to invisible, I can't access my Start Button
    '  Something seems to he holding on to things.
    '  What sort of stupidy have I envoked here?
    
    ' Controls Required:
    ' Command1
    ' Timer1
    ' Label1
    
    Option Explicit
    
    Public bStopThis             'get out of loop (Lable Flash)
    Public stFile As String      'file to check for content
    Public stDir As String       'dir of file
    Public sFired As Boolean     'used to stop timer from firing till past the minuite
    
    'get tic count API used in flickering the label caption (Label1)
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    
    Private Sub Form_Activate()
        Dim x    'store get tic count
        bStopThis = False
        Do
          Label1.ForeColor = IIf(Label1.ForeColor = vbWhite, vbRed, vbWhite)
          x = GetTickCount + 750                       'flash timer for label1
          Do Until x < GetTickCount Or Forms.Count = 0   'flash till
            DoEvents
          Loop
        Loop Until bStopThis = True Or Forms.Count = 0      'kill the loop
    End Sub
    
    Private Sub Command1_Click()
        bStopThis = True 'option to turn off blinking
        Form1.Visible = False
    End Sub
    
    Private Sub Form_DblClick()
    'kill the application
     bStopThis = True
     Unload Me
    End Sub
    
    Private Sub Form_Load()
        Timer1.Interval = 1000
        Timer1.Enabled = True
        'stDir = "K:\Working\"       'restore when done testing
        stDir = "c:\"   'testing data condition
        stFile = Dir$(stDir & "*.*")
        
        'label positioning on screen as well as command button positioning
        Label1.Left = (Screen.Width / 2) - (Label1.Width / 2)
        Label1.Top = (Screen.Height / 2) - (Label1.Height / 2)
        Command1.Left = (Screen.Width / 2) - (Command1.Width / 2)
        Command1.Top = Screen.Height - (Command1.Height + 2000)
        Me.WindowState = vbMaximized             'full view
    End Sub
    
    Private Sub Timer1_Timer()
        DoEvents
        Dim x                                'get formatted current time
        x = Format(Now, "HH:NN AM/PM")
        
        Select Case x
        'if these times and file is not empty and it has not been fired yet then fire it
          Case "10:10 AM", "10:14 AM", "10:17 AM", "10:20 AM" 'test
          'Case "08:50 AM", "11:50 AM", "01:50 PM", "03:50 PM"          'resore to this when test complete
              If stFile <> "" Then         'orders in file
               If sFired = False Then
                Form1.Label1.Caption = "Orders To Process"
                Form1.Visible = True
                sFired = True
               End If
           Else  'nothing in file
             If sFired = False Then
               Form1.Label1.Caption = "File Empty"
               Form1.Visible = True
               sFired = True
             End If
          End If
        'at any other time set the firesd condition to false
          Case Else
            sFired = False
        End Select
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  2. #2

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    RyeWhiskey..opps ..mean RyeBread...thanks for the thought but I tried that earlier.

    I have it now...don't know what the problem but I've seen this in VB from time to time. I copied all the code and dropped it into a new application and it now works fine.

    No explantaion as to why this happens but it has happened on occassion to me.

    Anyway...it is working like a charm now...weird one.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    FYI:

    I doubt this is the problem, but I've noticed that with a timer
    control, that if the code takes longer than the interval that
    the timer is set for, another timer event can fire off, which could
    lead to unexpected results. This occurs especially when you have a
    doevents in your timer event, and are accessing public variables
    that the timer event reacts to and sets based on its processing.

    I usually do a Timer1.enabled = False going into it,
    and a Timer1.enabled = True coming out, just to be safe.

    -Lou

  4. #4

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Actually, Ive taken the DoEvents out as the only reason I put it int there was to try and solve the problem. I thought I might not have had tome to get one of the Boolean results...desperation...
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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