Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Program Hangs 1

Status
Not open for further replies.

007MCSE

IS-IT--Management
Jan 3, 2003
51
US
I've got a Program running and endless Loop With a do while events.

Private Sub Timer1_Timer()
Static Temp As Integer
Temp = Temp + 1
Do While DoEvents()
If Temp Mod 2 = 0 Then Exit Do
Loop
End Sub

When the program is running, if you move the form with the mouse. The program locks up.
I know its because of the Do While Do Events.

But how do I stop this happening?
 
Not sure what you are trying to achieve I dont see the purpose of the code - the loop will never exit. Reasoning DoEvents() will always return an integer > 0 (True) as there is at least on form open, the one with the timer.
Temp will never increment as the timer wont get again fired while you are in the timer event.

Anyway to stop it from locking up add DoEvents in the loop.

Im not sure if this helps - am I missing something ???

cjw
 
I think what may be happening is a "stacking" of the event handler. When you call the DoEvents functions, you are releasing control to the OS to handle all of the outstanding events. During that time, especially if you move the form, there are quite a number of events that need to be handled, and a second invocation of the Timer event handler occurs before the first has actually completed. Event handlers are not recursive so you must do what you can to prevents repeated invocations of currently outstanding events.

What I would do is disable the timer during the event handling. Something like the following:

Private Sub Timer1_Timer()
Static Temp As Integer
Timer1.Enabled = False
Temp = Temp + 1
Do While DoEvents()
If Temp Mod 2 = 0 Then Exit Do
Loop
Timer1.Enabled = True
End Sub Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
The program is a light controller and the loop does work. Its sequencing lights. The loop does stop with user intervention from within the main form.

The problem is as soon as you move the Form window when the program is running, it halts the loop because of the DoEvents. Thats the problem I want the loop to keep running if a user moves the window

Gary
 
Perhaps you should post the entire code of the Timer event handler. The code, as shown, does not provide any insight as to how these lights are being sequenced. Also, what is the Timer interval? Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
The Timer Routine is a Subroutine called up from within the main program and the Timer Interval is set by the user from within a setup subform. When they enter a timer value it is stored in a variable called T1.

Below is a section of the program so you can see how the Timer1_Timer Loop fits into the main program.

Out PortAddress, &H2
LED2.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED2 FillColor = Black

This is just one routine to switch on Pin 3 of the Parallel Port and at the same time Lights an LED Graphic (on the screen)and turns it Red. Once it has finished the Timer routine (T1) It Switches off Pin2 and turns the LED Graphic back to Black.
Then it moves on to the next Pin on the parallel port and lights that associated LED Graphic on the screen and so on

Hope this helps
Gary
 
Although you can explicitly call an event handler, the timer event is triggered by the system at the timer's defined interval.

It seems that you're trying to use the timer as a delay mechanism to control program execution speed. You might try something like the following:

Declare a public variable called Delay.
Code:
Timer1.Interval = T1
Timer1.Enabled = False

Out PortAddress, &H2
LED2.FillColor = Red
Delay = True
Timer1.Enabled = True
Do While (Delay = True)
   DoEvents
Loop
LED2 FillColor = Black
...
And the timer event would be the following:
Code:
Private Sub Timer1_Timer()
   Timer1.Enabled = False
   Delay = False
End Sub
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi Cajun

I added the following, but changed Timer1 to Timer3 so that I didn't have to change the current program



Private Sub Delay()
'Declare a public variable called Delay.
t1 = 300
Timer3.Interval = t1
Timer3.Enabled = False
End Sub

Private Sub Test_Click()
Out PortAddress, &H2
LED2.FillColor = Red
Delay = True
Timer3.Enabled = True
Do While (Delay = True)
DoEvents
Loop
LED2.FillColor = Black
End Sub

Private Sub Timer3_Timer()
Timer3.Enabled = False
Delay = False
End Sub

It didn't work...What am I doing wrong.
Please bare with me as i'm new to programing

Thanks very much
Gary
 
I do not believe that it is a good idea, nor good programming practice to have a variable and a procedure as the same name.

Delcare a public variable at the top of the code, before any of the routines:
Code:
Option Explicit
Dim bDelay as Boolean ' public declaration

Private Sub Form_Load()
   bDelay = False  ' Initialize it to false
End Sub

Private Sub SetDelay() ' Use Different Name
   t1 = 300
   Timer3.Interval = t1
   Timer3.Enabled = False
End Sub

Private Sub Test_Click()
   Out PortAddress, &H2
   LED2.FillColor = Red
   bDelay = True
   Timer3.Enabled = True
   Do While (bDelay = True)
      DoEvents
   Loop
   LED2.FillColor = Black
End Sub

Private Sub Timer3_Timer()
   Timer3.Enabled = False
   bDelay = False
End Sub
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi Cajun

Thats starting to work now. It does output to the Parallel port and it does light the LED.
But the program halts at "Timer3.Enabled = True"
In the "Test_Click" routine with a "Runtime error 424, Object required"

Thanks again for your help
Gary
 
I would first check the spelling of everything.

In a previous post, you stated that you "but changed Timer1 to Timer3 so that I didn't have to change the current program". Did you actually change the name of the Timer control on the form, or only change the names of the procedures. If you only changed the names of the procedures, then you should either, change the name of the control to Timer3, or add another Timer, called Timer3 to the form.

I also suspect that the SetDelay function is not being called since you did not get the object required error from there. You need to call it at sometime to be sure that the timer has the proper interval.

Another possibility is that there is a scope problem, in other words, the Test_Click function is not in the same form which contains the Timer3 control? Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Cajun

Ok....I think we're getting there.
Yes you were right I forgot to add Timer3 to the form.
I've also called up the "Set delay"

I've stepped through the routine and it goes through the routine once and then gets caught in the loop

Do While (bDelay = True)
DoEvents
Loop

Instead off going back to the top of the routine

Gary
 
Be sure that you are enabling Timer3 each time immediately before entering the delay loop.

Timer3.Enabled = True
Do While (bDelay = True)
DoEvents
Loop Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Timer3.Enabled is enabled just before the loop
and True is set to True.

Gary
 
I Still can't get it to go back to the Top of the routine
 
Sorry didn't get back sooner --

Perhaps you should post all of the relavent code for review. Need to see how the various pieces are interacting in hopes to find where the breakdown is. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi Cajun

I know the program is messy and there are other ways off doing things. But i'm going to tidy it up once I've got all the bugs out.

The program is below:-

' These two declarations for the inpout32.dll are for getting data from the
' parallel port, Inp, and sending data to the parallel port, Out.

Private Declare Function Inp Lib "inpout32.dll" _
Alias "Inp32" (ByVal PortAddress As Integer) As Integer

Private Declare Sub Out Lib "inpout32.dll" _
Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)

' Declare the variables for the Port Address and the Value to send to the port
Dim PortAddress As String
' public declaration
Dim bDelay As Boolean
' Declare the Color variables for LED Colors
Dim Green As String
Dim Red As String
Dim Clear As String
Dim Blue As String
Dim Black As String
Dim Purple As String
Dim Orange As String
Private Sub Form_Load()
' The Port Address is the HEX address of Your parallel port. You find this
' by going to your device manager and clicking on the Resources tab for your
' parallel port. &H378 is the default but if yours isn't change it below.

PortAddress = &H378
bDelay = False ' Initialize it to false
Green = vbGreen
Red = vbRed
Clear = vbWhite
Blue = vbBlue
Black = vbBlack
Purple = 8388736
Orange = 33023

Call Timer2_Timer

End Sub
Private Sub Clear_LEDS()
Out PortAddress, &H0
LED1.FillColor = Black
LED2.FillColor = Black
LED3.FillColor = Black
LED4.FillColor = Black
LED5.FillColor = Black
LED6.FillColor = Black
LED7.FillColor = Black
LED8.FillColor = Black
End Sub

Private Sub Stop_Click()

Out PortAddress, &H0
Unload PPortLC1
Dim frmPPortLC1 As PPortLC1
Set frmPPortLC1 = New PPortLC1
frmPPortLC1.Show vbModal, Me
End Sub
Public Sub LEDColors_Click() 'openform.LEDColors'
Dim frmLedColours As LEDColors
Set frmLedColours = New LEDColors
frmLedColours.Show vbModal, Me
End Sub
Public Sub Speed_Click() 'openform.SpeedSetup'
Out PortAddress, &H0
Dim frmSpeedSetup As SpeedSetup
Set frmSpeedSetup = New SpeedSetup
frmSpeedSetup.Show vbModal, Me
End Sub
Private Sub ExitCmd_Click()
Out PortAddress, &H0
End
End Sub
Private Sub Timer1_Timer()
Static Temp As Integer
Temp = Temp + 1
Do While DoEvents()
If Temp Mod 2 = 0 Then Exit Do
Loop
End Sub
Private Sub SetDelay() ' Use Different Name
T1 = 10
Timer3.Interval = T1
Timer3.Enabled = False
End Sub
Private Sub Test_Click()
'Call SetDelay
'Out PortAddress, &H2
'LED2.FillColor = Red
'bDelay = True
'Timer3.Enabled = True
'Do While (bDelay = True)
'DoEvents
'Loop
'LED2.FillColor = Black
'Do

Call SetDelay

Out PortAddress, &H1
LED1.FillColor = Red
LED1.FillColor = Black
Out PortAddress, &H2
LED2.FillColor = Red
LED2.FillColor = Black
bDelay = True
Timer3.Enabled = True

Do While (bDelay = True)


DoEvents
Loop


End Sub

Private Sub Timer3_Timer()
Timer3.Enabled = False
bDelay = False
End Sub

Private Sub Timer2_Timer()
Clock.Text = Format(Now, "hh:mm:ss am/pm")
End Sub
Private Sub P1S4_Click()
P1S4.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1
Do
Call Clear_LEDS
Out PortAddress, &H1
LED1.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black

Out PortAddress, &H2
LED2.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED2.FillColor = Black

Out PortAddress, &H4
LED3.FillColor = Clear
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black

Out PortAddress, &H8
LED4.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED4.FillColor = Black
Loop While DoEvents

End Sub
Private Sub P1S8_Click()
P1S8.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H1
LED1.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black

Out PortAddress, &H2
LED2.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED2.FillColor = Black

Out PortAddress, &H4
LED3.FillColor = Clear
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black

Out PortAddress, &H8
LED4.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED4.FillColor = Black

Out PortAddress, &H10
LED5.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED5.FillColor = Black

Out PortAddress, &H20
LED6.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED6.FillColor = Black

Out PortAddress, &H40
LED7.FillColor = Clear
Timer1.Interval = T1
Timer1_Timer
LED7.FillColor = Black

Out PortAddress, &H80
LED8.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED8.FillColor = Black

Loop While DoEvents
End Sub
Private Sub Pairs_Click()
Pairs.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H3
LED1.FillColor = Green
LED2.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black
LED2.FillColor = Black

Out PortAddress, &HC
LED3.FillColor = Red
LED4.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black
LED4.FillColor = Black

Out PortAddress, &H30
LED5.FillColor = Clear
LED6.FillColor = Clear
Timer1.Interval = T1
Timer1_Timer
LED5.FillColor = Black
LED6.FillColor = Black

Out PortAddress, &HC0
LED7.FillColor = Blue
LED8.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED7.FillColor = Black
LED8.FillColor = Black
Loop While DoEvents

End Sub
Private Sub RolloverPairs_Click()
RolloverPairs.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H3
LED1.FillColor = Red
LED2.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black

Out PortAddress, &H6
LED3.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED2.FillColor = Black

Out PortAddress, &HC
LED4.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black

Out PortAddress, &H18
LED5.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED4.FillColor = Black

Out PortAddress, &H30
LED6.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED5.FillColor = Black

Out PortAddress, &H60
LED7.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED6.FillColor = Black

Out PortAddress, &HC0
LED8.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED7.FillColor = Black

Out PortAddress, &H81
LED1.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED8.FillColor = Black
Loop While DoEvents

End Sub
Private Sub Triple_Click()
Triple.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H7
LED1.FillColor = Green
LED2.FillColor = Green
LED3.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black
LED2.FillColor = Black
LED3.FillColor = Black

Out PortAddress, &H38
LED4.FillColor = Red
LED5.FillColor = Red
LED6.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED4.FillColor = Black
LED5.FillColor = Black
LED6.FillColor = Black

Out PortAddress, &HC1
LED7.FillColor = Clear
LED8.FillColor = Clear
LED1.FillColor = Clear
Timer1.Interval = T1
Timer1_Timer
LED7.FillColor = Black
LED8.FillColor = Black
LED1.FillColor = Black

Out PortAddress, &HE
LED2.FillColor = Blue
LED3.FillColor = Blue
LED4.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED2.FillColor = Black
LED3.FillColor = Black
LED4.FillColor = Black

Out PortAddress, &H70
LED5.FillColor = Green
LED6.FillColor = Green
LED7.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED5.FillColor = Black
LED6.FillColor = Black
LED7.FillColor = Black

Out PortAddress, &H83
LED8.FillColor = Red
LED1.FillColor = Red
LED2.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED8.FillColor = Black
LED1.FillColor = Black
LED2.FillColor = Black

Out PortAddress, &H1C
LED3.FillColor = Clear
LED4.FillColor = Clear
LED5.FillColor = Clear
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black
LED4.FillColor = Black
LED5.FillColor = Black

Out PortAddress, &HE0
LED6.FillColor = Blue
LED7.FillColor = Blue
LED8.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED6FillColor = Black
LED7.FillColor = Black
LED8.FillColor = Black
Loop While DoEvents
End Sub
Private Sub TripRoll_Click()
TripRoll.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H7
LED1.FillColor = Green
LED2.FillColor = Green
LED3.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black

Out PortAddress, &HE
LED4.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED2.FillColor = Black

Out PortAddress, &H1C
LED5.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black

Out PortAddress, &H38
LED6.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED4.FillColor = Black

Out PortAddress, &H70
LED7.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED5.FillColor = Black

Out PortAddress, &HE0
LED8.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED6.FillColor = Black

Out PortAddress, &HC1
LED1.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED7.FillColor = Black

Out PortAddress, &H83
LED2.FillColor = Green
Timer1.Interval = T1
Timer1_Timer
LED8.FillColor = Black
Loop While DoEvents
End Sub
Private Sub OutToInSeq_Click()
OutToInSeq.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H81
LED1.FillColor = Blue
LED8.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black
LED8.FillColor = Black

Out PortAddress, &H42
LED2.FillColor = Blue
LED7.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED2.FillColor = Black
LED7.FillColor = Black

Out PortAddress, &H24
LED3.FillColor = Blue
LED6.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black
LED6.FillColor = Black

Out PortAddress, &H18
LED4.FillColor = Blue
LED5.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED4.FillColor = Black
LED5.FillColor = Black
Loop While DoEvents

End Sub
Private Sub InToOutSeq_Click()
InToOutSeq.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H18
LED4.FillColor = Blue
LED5.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED4.FillColor = Black
LED5.FillColor = Black

Out PortAddress, &H24
LED3.FillColor = Blue
LED6.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black
LED6.FillColor = Black

Out PortAddress, &H42
LED2.FillColor = Blue
LED7.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED2.FillColor = Black
LED7.FillColor = Black

Out PortAddress, &H81
LED1.FillColor = Blue
LED8.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black
LED8.FillColor = Black

Loop While DoEvents

End Sub
Private Sub CrossOver_Click()
CrossOver.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H81
LED1.FillColor = Blue
LED8.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black
LED8.FillColor = Black

Out PortAddress, &H42
LED2.FillColor = Blue
LED7.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED2.FillColor = Black
LED7.FillColor = Black

Out PortAddress, &H24
LED3.FillColor = Blue
LED6.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black
LED6.FillColor = Black

Out PortAddress, &H18
LED4.FillColor = Blue
LED5.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED4.FillColor = Black
LED5.FillColor = Black

Out PortAddress, &H18
LED4.FillColor = Blue
LED5.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED4.FillColor = Black
LED5.FillColor = Black

Out PortAddress, &H24
LED3.FillColor = Blue
LED6.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black
LED6.FillColor = Black

Out PortAddress, &H42
LED2.FillColor = Blue
LED7.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED2.FillColor = Black
LED7.FillColor = Black

Out PortAddress, &H81
LED1.FillColor = Blue
LED8.FillColor = Blue
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black
LED8.FillColor = Black
Loop While DoEvents

End Sub
Private Sub PlusOne_Click()
PlusOne.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H1
LED1.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H2
LED2.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H4
LED3.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H8
LED4.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H10
LED5.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H20
LED6.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H40
LED7.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H80
LED8.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Loop While DoEvents
End Sub
Private Sub MinusOne_Click()
MinusOne.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H80
LED8.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H40
LED7.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H20
LED6.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H10
LED5.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H8
LED4.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H4
LED3.FillColor = Red
Timer1.Interval = T1
Timer1_Timer


LED2.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H2
LED1.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
Loop While DoEvents
End Sub

Private Sub PlusMinus1_Click()
PlusMinus1.BackColor = Green
Open "c:\Program Files\PPortLC1\Data\Speed.ini" For Input As #1
Input #1, T1
Close #1

Do
Call Clear_LEDS
Out PortAddress, &H1
LED1.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H2
LED2.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H4
LED3.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H8
LED4.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H10
LED5.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H20
LED6.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H40
LED7.FillColor = Red
Timer1.Interval = T1
Timer1_Timer

Out PortAddress, &H80
LED8.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED8.FillColor = Black

Out PortAddress, &H7F
LED7.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED7.FillColor = Black

Out PortAddress, &H3F
LED6.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED6.FillColor = Black

Out PortAddress, &H1F
LED5.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED5.FillColor = Black

Out PortAddress, &HF
LED4.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED4.FillColor = Black

Out PortAddress, &H7
LED3.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED3.FillColor = Black

Out PortAddress, &H3
LED2.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED2.FillColor = Black

Out PortAddress, &H1
LED1.FillColor = Red
Timer1.Interval = T1
Timer1_Timer
LED1.FillColor = Black
Out PortAddress, &H0

Loop While DoEvents
End Sub


Thanks for all your help
Gary
 
The only time that you're using Timer3 is the one time inside the Test_Click function. I think that the continued use of Timer1 is the root of your problem. If I understand your intentions correctly, then you don't want to use Timer1 at all. Everywhere that you have the following two lines of code:
Code:
   Timer1.Interval = T1
   Timer1_Timer
Replace those two lines with
Code:
   bDelay = True
   Timer3.Enabled = True
   Do While (bDelay = True)
      DoEvents
   Loop
Or better yet, take the above code, and put it in its own routine, and then replace your two Timer1 lines with a call to this routine.

I do not think its a good idea to explicitly call event handlers from within the code. I don't think you should invoke the Timer event, but rather, you should activate the Timer and let the system trigger the event at the appropriate time. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Yes thats the plan to get rid off the timer1 routine and use your new routine once I can get it to work.

I will put it into a subroutine once I get it working correctly.

I'll try it later today and let you know.

Thanks again for all your help
 
Hi Cajun

I just tryed it and it works
The problem is it our cycles through once.
The idea of the original timer routine was for it to keep looping and sequence the LEDs and outputs to the Parallel port until the user stops it.

Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top