Results 1 to 3 of 3

Thread: Continuous Operation

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    6

    Continuous Operation

    I've got a program I'm creating that polls industrial units through the serial port. These units must be polled continuously at the quickest rate possible, and must run endlessly. So I have two questions:

    1. How can I create a really small, small delay (about 10 ms)? The VB timer only allows me to have delays accurate to approx 70 ms.

    2. How can I have my program run continuously without running out of stack memory. The way it is now, once started, it calls a sub which calls another sub which calls the first sub again. I don't know how else to make it run endlessly, but the stack fills up so quickly!

    Any ideas? Any help would be appreciated.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You can use the Sleep API to pause and put your code in a loop.
    VB Code:
    1. Private Declare Sub Sleep _
    2.  Lib "kernel32" ( _
    3.  ByVal dwMilliseconds As Long)
    4.  
    5. Private blnStop As Boolean
    6.  
    7. Private Sub doTheWork()
    8.     Do While True 'an never ending loop
    9.          'do the work
    10.          Sleep 10
    11.          DoEvents
    12.          If blnStop Then
    13.              Exit Sub
    14.          End If
    15.     Loop
    16. End Sub
    17.  
    18. Private Sub Form_Unload()
    19.     blnStop = True
    20. End Sub
    Best regards

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    6

    Works

    Thanks.

    It seems to be working now. I feel kinda silly because it was so simple!

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