Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,443 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,305 people online right now. Registration is fast and FREE... Join Now!




Not Responding Error

 
Reply to this topicStart new topic

Not Responding Error, Error when running my counter program

cprua
3 Jan, 2008 - 08:37 AM
Post #1

New D.I.C Head
*

Joined: 3 Jan, 2008
Posts: 1

I'm creating a clock for circuit training that will countdown from 30 to 0 then an interval countdown from 15 to 0.
I'll then repeat the process and finally a 3rd 30 sec countdown.
The next part will countdown from 60 secs to 0 and then an interval from 30 to 0.
That will complete one station and I will repeat the entire process 10 times.
The programming part is fine and I can add the "bells and whistles" later.

However I am having problems and getting a "Not Responding" error after approx 5 seconds - This dissappears when the end of the program is reached and both counters are at correct at the end, but how do I prevent the not responding.


CODE
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)


CODE
Public Sub RunCircuit()
        Dim CIRCUIT_TIME As Integer
        Dim INTERVAL_TIME As Integer
        Dim MyCounter As Integer
        CIRCUIT_TIME = 30
        INTERVAL_TIME = 15
        For MyCounter = 1 To 30
            Me.Label1.Text = CIRCUIT_TIME
            Me.Label1.Refresh()
            Sleep(1000)
            CIRCUIT_TIME = CIRCUIT_TIME - 1
        Next MyCounter
        For MyCounter = 1 To 15
            If Me.Label2.Text = "10" Then Me.Label2.ForeColor = Color.Orange
            If Me.Label2.Text = "5" Then Me.Label2.ForeColor = Color.Red
            Me.Label2.Text = INTERVAL_TIME
            Me.Label2.Refresh()
            Sleep(1000)
            INTERVAL_TIME = INTERVAL_TIME - 1
        Next MyCounter

    End Sub


Thank you
User is offlineProfile CardPM
+Quote Post

LookNAO
RE: Not Responding Error
3 Jan, 2008 - 09:34 AM
Post #2

D.I.C Head
**

Joined: 28 Dec, 2007
Posts: 66



Thanked: 1 times
My Contributions
Inside your For/Next loops put a DOEVENTS statement.

This allows windows to do it's "House cleaning"... memory management, update the screen, update the clock, etc...

If you never give windows an chance to do this your program will hang. For good practice it is good to do this if there is alot of lines of code and definitely in your DO/While or For/Next loops.

p.s. Make sure in your form_terminate to put "end"





User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 02:15PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month